0
votes

What is the difference between the two mentioned below

void func1() { print('Hello World') }

and

func1() { print('Hello World') }

2

2 Answers

0
votes

If you omit types that cannot be inferred (whether return types, parameter types, etc.), the default type is dynamic.

You can verify this yourself by going to https://dartpad.dartlang.org/ , entering a function with no return type:

func1() { print('Hello World'); }

and clicking on it. DartPad's Documentation pane will tell that func1 has a return type of dynamic.

0
votes

If you declare a function void, you're explicitly declaring that it is intended to return no arguments, and it will therefore generate a compile error if you put e.g. a "return 0" into it.

Leaving out the void you're accepting default behavior.