Using continue / pause in the Boolean statement [V8]
source link: https://www.codesd.com/item/using-continue-pause-in-the-boolean-statement-v8.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Using continue / pause in the Boolean statement [V8]
true && (function () { console.log('executed'); })()
is ok, then why
true && continue;
true && (continue);
doesn't work, e.g. V8 (Node) throws:
SyntaxError: Unexpected token continue
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 true
and (function() { ... })()
are expressions - a boolean expression evaluating to true
, and a function expression (wrapped inside parentheses and then called) evaluating to undefined
.
continue
is a statement, so you cannot use &&
. You'll have to use if
because if
does 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.
Related Articles
Using a variable after the if statement
Problems with the Boolean statement and the if statement in python
Use a result of the if statement in another if
Is it possible to use continuations to make the tail fold recursive?
How to show / hide a youtube video using jquery without losing the current state?
Sql Server Order by nvarchar field using a substring in the select statement
Using NSUserDefaults to store the UISwitch state
Use jQuery to add the yield statement to the application.html.erb body?
How to use string enumerations in the switch statement
Return several fields using a box in the select statement of the sql server
unexpected character after the line continuation character in the if statement
Rails, how to use a block in the where statement
How to use HttpClient to keep the connection state for a later process after restarting the application?
Using variable contents in the select statement
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK