Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart => expr syntax only an expression not a statement is partial

Tags:

dart

Dart => expr syntax notes:

Only an expression—not a statement—can appear between the arrow (=>) and the semicolon (;).

case:

sayHello(String name) => print("Hello, $name");

Here I think print is a statement.

Generally we agree:

  • Expression: which can be calculated as a value.
  • Statement: a piece of code which can do logic processing.

=> can be understood as a single-line function, a expression or a single-line statement(Function Expression).

like image 697
conan Avatar asked May 21 '26 23:05

conan


1 Answers

if ..., for ..., switch ..., would be statements. print() is a function call that evaluates to void and is an expression as a + b which is also a function call like a.operator+(b) just with a different syntax.

like image 50
Günter Zöchbauer Avatar answered May 23 '26 15:05

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!