I know what an expression is and I know what a statement is in JavaScript. But what are expression statement in JavaScript?
I know that the ternary operator (... ? ... : ...) and function calls (alert("Hello World")) are expression statements. But what else? Or are only these two considered expression statements?
Top comments (2)
An expression in Javascript (and pretty much all languages, with variation) at the most basic level is just "anything that takes on a value".
So the number
42
or the string"Hello world"
or7 + 3
because they all "take on" a value (42, Hello world, and 10).As you can tell from this definition, almost everything is an expression. The only other "type" of thing are statements, which there's a more limited number of (depending on language). Things like
if / else
in Javascript orfor
because these things don't take on values (you couldn't write something likelet variable = if (true) { ... }
).In Kotlin you can ...