|
|
|
|
|
by simiones
1440 days ago
|
|
My point was that GP's rule of thumb (if it has a keyword, it's a statement, otherwise is an expression) is wrong on both ends. 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). |
|
I do agree!
Sorry to bother you but I am a bit confused about this part of your comment:
> `alert("Hello, World!")` or `doSomething()` are usually statements, not expressions;
Can you please clarify what you mean here? Do you mean `alert("Hello, World!")` is an expression? Or do you mean it is not an expression? Or did you mistype?
Your `console.log( /* put thing here */ )` test is a pretty good one and indeed `console.log(alert("Hello, World!"))` passes this test.