Home  >  Article  >  Web Front-end  >  JavaScript expressions and statements

JavaScript expressions and statements

巴扎黑
巴扎黑Original
2017-07-20 15:59:051449browse

if statement

ternary operator

Expression 1 ? Expression 2 : Expression 3
is a simplified way of writing the if...else statement

switch statement

switch (expression) {
case constant 1:
statement;
break;
case constant 2:
statement;
break;
case constant 3:
statement;
break;

case constant n:
statement;
break;
default:
statement;
break;
}

break can be omitted, if omitted, the code will continue to execute the next case
switch statement uses the congruence operator when comparing values, so no type conversion will occur (For example, the string '10' is not equal to the value 10)

Implicit conversion of Boolean type

Convert to true Non-empty string non-0 number true Any object
Convert to false Empty string 0 false null undefined

for loop

// The expressions of the for loop are separated by ; characters. Never write,
for (initialization expression Formula 1; Judgment expression 2; Auto-increment expression 3) {
// Loop body 4
}

while (loop condition) {
//Loop body
}

do{
// Loop body;
} while (loop condition);

continue and break

break: Immediately jump out of the entire loop, that is, the loop ends, and start executing the content after the loop (jump directly to the braces)

continue: Immediately jump out of the current loop and continue with the next loop (jump to i++)

The above is the detailed content of JavaScript expressions and statements. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn