3 ms·
> 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. I do agree! Sorry to bother
by mxben 4y 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.
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.
- tsimionescu 4y agoI meant that you would usually encounter those as statements, as in the following example: function foo() { alert("Hello, World!"); doSomething(); } And not as expressions (as in your example of `console.log(alert("Hello, World"))`. Btw, a better rule of thumb for JS is "if you can add `;` after it and not alter the meaning of the program, it's a statement; otherwise it's an expression".