Conditional Judgment Statement if statement/switch statement

Source: Internet
Author: User

    • 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>
    • Switch statement

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.