4

Using continue / pause in the Boolean statement [V8]

 3 years ago
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]

advertisements
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.

Tags javascript

Related Articles

Using a variable after the if statement

Wondering what is faster and/or what is better practice when checking a variable in an if statement and then using it again after the if statement. Like if var_A + var_B > 10: var_C = var_A + var_B or var_temp = var_A + var_B if var_temp > 10: var_C

Problems with the Boolean statement and the if statement in python

def test(): boo = True enter = int(raw_input("Enter something: ")) if enter > 0: boo = False print "Did it work?!" else: print "Still working..." while boo == True: test() test() So this bit of code seems to only work if t

Use a result of the if statement in another if

I am writing a quiz app, where you get marks as you answer the correct questions and your score increases, and I have to use if statements. Please does any one know how to use a value in an if statement in another if statement! I'm kinda confused abo

Is it possible to use continuations to make the tail fold recursive?

The following blog article shows how in F# foldBack can be made tail recursive using continuation passing style. In Scala this would mean that: def foldBack[T,U](l: List[T], acc: U)(f: (T, U) => U): U = { l match { case x :: xs => f(x, foldBack(xs,

How to show / hide a youtube video using jquery without losing the current state?

I'm building a jquery ajax page that shows a list of youtube videos. I've got two views on the page (list & video), which are built as LI elements, floated left, inside a UL element. I built it this way because the transition between the views is don

Sql Server Order by nvarchar field using a substring in the select statement

I want to use Order by clause in select statement to Order the nvarchar field in the following data. 1/2013 1/2014 2/2013 3/2013 5/2010 25/2013 115/2013 26/2014 I want to Order by result like the following: 5/2010 1/2013 2/2013 3/2013 25/2013 115/201

Using NSUserDefaults to store the UISwitch state

I am trying to persist the UISwitch state in my settings view of my application. Basically it is a UITableView and contains a few switches to get the user preferences. The below code explains how the switches are constructed (only one switch construc

Use jQuery to add the yield statement to the application.html.erb body?

I'm working on a rails app and would like to hide away some code a bit more thoroughly. At the moment my application.html.erb just has a <%= yield %> statement in the and I'd like to move that creation to jQuery. I have tried putting this into my ap

How to use string enumerations in the switch statement

This question already has an answer here: Java: using switch statement with enum under subclass 5 answers public class TestingGen { /** * @param args */ public enum Types { TYPE1("TYPE1"), TYPE2("TYPE2"); private String type; private T

Return several fields using a box in the select statement of the sql server

I have a table tb3 wherein id,name,sal are to be displayed using select statement and city,descrip fields need to be diaplayed in the same select statement only when the flag is 'Y'. How do I do this using case statements? id name sal city descrip fl

unexpected character after the line continuation character in the if statement

This is my code for removing vowels from given string.My code shows unexpected character after line continuation character in if statement condition?can anyone help def anti_vowel(text): r=len(text) new=[] for i in range(0,r): if lower.text[i]!='a' a

Rails, how to use a block in the where statement

Taken from this stackoverflow-question, one can use a block for a query, like this: Consumer.find do |c| c.id == 3 end I want to do the same with a "where" query, for example: mainCustomers = Customer.where do |c| c.id == c.main end When I do th

How to use HttpClient to keep the connection state for a later process after restarting the application?

My app use HttpPost to login a discuss so I can get some pages that must need to be loged in used the same httpClient instance . But if my app was quit and restart again after sometime. Can I use the httpClient response that keep me the state that I

Using variable contents in the select statement

I have a plsql function where I'm first receiving the field name of an other table in a select statement. Now I want to get the value of the field of this other table. In the variable fieldName is the fieldname of the table I need. What I tried so fa

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK