|
|
|
|
|
by mxben
1440 days ago
|
|
`alert("hello")` is an expression and also a statement. a = alert("hello"); // Assigns a to undefined
What isn't an expression? An `if` statement is not an expression. a = if (true) alert("hello"); // Uncaught SyntaxError: Unexpected token 'if'
|
|
A JS program is composed out of statements, which may contain expressions. In particular, in JS, any expression is also valid as a statement. This is not true in all languages (for example, `2` is not a valid statement in Go).