3 ms·
Probably worth adding "(javascript)" to the HN title - for non-JS see @nivertech's excellent comment here. I may be wrong but I actually think the explanation
by lucideer 4y ago
Probably worth adding "(javascript)" to the HN title - for non-JS see @nivertech's excellent comment here.
I may be wrong but I actually think the explanation can be a little simpler than the article posits: an expression (in JS) is something that returns a value. That's it. The value can be undefined/void, but it's still a value being returned.
One important detail the article seems to miss that I've come across whie explaining JS syntax to JSX-learners is that, while statements usually contain expressions, expressions can also contain statements. This is because a function definition returns a value (the function instance) & obviously function bodies can contain any JS syntax. This is useful if you (for some odd reason) want to embed a statement in some JSX code (since JSX only supports JS expressions).