dartexpressiondart-pub

Difference between an Expression and Statement in Dart?


Since different languages have different definitions for an expression and a statement, what is the difference between them in Dart?


Solution

  • I'm still new to Dart but with previous knowledge (and reading dart language tour):

    A statement contains expressions, but an expression can’t contain a statement.

    Above is my explanation of bullet point I tried to simplify for you, found when reading language tour on category important concepts that goes like this:

    Dart has both expressions (which have runtime values) and statements (which don’t). For example, the conditional expression condition ? expr1 : expr2 has a value of expr1 or expr2. Compare that to an if-else statement, which has no value. A statement often contains one or more expressions, but an expression can’t directly contain a statement.