if
true && (function () { console.log('executed'); })()
is ok, then why
true && continue;
or
true && (continue);
doesn’t work, e.g. V8 (Node) throws:
SyntaxError: Unexpected token continue
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In JavaScript, there are expressions and statements. Statements can contain expressions, but not the other way round. The statement
true && false;is an expression statement.&&expects two expressions.Both
trueand(function() { ... })()are expressions – a boolean expression evaluating totrue, and a function expression (wrapped inside parentheses and then called) evaluating toundefined.continueis a statement, so you cannot use&&. You’ll have to useifbecauseifdoes accept a statement to be run when the condition is true.It’s correct behaviour according to the specification and should not be V8-specific.