- An if (conditional expression) statement
The IF statement is a conditional judgment statement, and for an expression in parentheses in the IF statement, ECMAScript automatically calls the Boolean () transformation function to convert the result of the expression to a Boolean value. If the value is true, execute the following statement, or do not execute the
<script type= "Text/javascript" >var box = 100; if (Box > 50) // IF statement if it returns FALSE, only the following statement is not executed alert (box); // The second statement is independent of the IF statement, so alert is executed (" Whether it is true or FALSE, it will execute to! "); </script>
<script type= "Text/javascript" >var box = 10< Span style= "color: #000000;" >; if (Box > 50) {// here is a compound statement treated as a statement, also called a code block alert (box); Alert (, whether true or false, will execute to!) "); } </script>
- if (conditional expression) {statement;} else{statement;}
<script type= "Text/javascript" >var box = +; if (Box >) { alert(' box is greater than 'else { alert (' box less than ');} </script>
- if (conditional expression) {statement;} else if (conditional expression) {statement;} ... else{statement;}
<script type= "Text/javascript" >varbox = 98;if(Box >= 90) {alert (Methyl);} Else if(Box >= 80) {alert (Ethyl);} Else if(Box >= 70) {alert (Isopropyl);} Else if(Box >= 60) {alert (Failed);} Else{alert (' Fail ');} </script>
Multiple conditional judgments, for comparison of multiple values equal
<script type= "Text/javascript" >varbox=2;Switch(box) {//The Switch box box is the variable you want to compare Case1://Case 1: equivalent to the IF statement (box = = 1), if box is 1Alert (' One '); Break;//Break exits in the middle to prevent penetration Case2://if (box = = 2)Alert (' Both '); Break; Case3: Alert (' Three '); Break; default://equivalent to the else in the IF statementAlert (' Error! ‘);}</script>
Conditional Judgment Statement if statement/switch statement