Re:Statements vs. Expressions
by hibbelig on Thursday July 14, 2022 @05:59AM
(#32094002)
I can't think of an example where
compiles but
does not compile. I think all expressions are statements.
[ Parent
| on HN ]
Some languages forbid "obviously pure" expressions like "0" as statements (since using them as a statement is probably a mistake).
I think I was saying that Javascript is not one of them.
Interesting! Any examples of such languages?
Java is one popular example. You get "error: not a statement".
Right. They're not mutually exclusive -- hence the "both, either, or neither"
My point was that there are four combinations, and "both, either, or neither" suggests that all four can happen. But actually, only three out of four can happen.
It can be both a statement and an expression. Yes.
It can be neither a statement nor an expression. Yes.
It can be a statement but not an expression. Yes.
But the case that it is an expression but not a statement: this case never happens.