JavaScript-if the branch is determined

determining if the basic syntax
1.If (expression) {} program execution
when the result of the expression is true, the program execution
when the expression evaluates to false, the program is not performed

var pay = 50000;
if(pay > 100000){
     console.log('恭喜我自己,获得 100 元零花钱');
 }

Almost continuousl (expression) {1} program Program the else {2}
if the expression 1 is true, the program execution
when the expression evaluates to false, execution program 2

var pay = 150000;
if(pay > 100000){
     console.log('恭喜我自己,获得 100 元零花钱');
}else{
     console.log('恭喜我自己,获得 50 元零花钱');
}

3.If (Condition 1) program {1} else if (condition 2) Program {2} else if (condition 3) 3} ... {program
when the condition 1, an execution program
satisfies the condition 2, 2 executes a program
which satisfies the conditions which condition the implementation of the program
to determine the order from top to bottom, if the first condition is satisfied, the latter condition will no longer execute judgment and
will eventually execute a program
all of the conditions are not met, the content is not performed of

var pay = 50000;
if(pay > 100000){
     console.log('恭喜我自己,获得 100 元零花钱');
 }else if(pay > 90000 && pay < 100000){
     console.log('恭喜我自己,获得 90 元零花钱');
 }else if(pay > 80000 && pay < 90000){
     console.log('恭喜我自己,获得 80 元零花钱');
 }else if(pay > 70000 && pay < 80000){
     console.log('恭喜我自己,获得 70 元零花钱');
 }

Anything, just ... (Condition 1) program {1} else if (condition 2) Program {2} else if (condition 3) Program {3} ... else {}
from top to bottom executed from a first start determination
meet current after the conditions for implementation of the corresponding program, after the judgment and the program will not execute the
program if all the conditions are not met, it performs else inside

if(pay >= 100000){
    console.log('恭喜我自己,获得 100 元零花钱');
}else if(pay >= 90000 && pay < 100000){
    console.log('恭喜我自己,获得 90 元零花钱');
}else if(pay >= 80000 && pay < 90000){
    console.log('恭喜我自己,获得 80 元零花钱');
}else if(pay >= 70000 && pay < 80000){
    console.log('恭喜我自己,获得 70 元零花钱');
}else{
    console.log('工资少于7W,我只能跪搓衣板');
}

Note: if statement is written judgment conditions, pay attention to setting limit values.

Published 21 original articles · won praise 3 · Views 330

Guess you like

Origin blog.csdn.net/qq_44531034/article/details/104828776