Usage of JavaScript if...else statements

Source: Internet
Author: User

Web page Special effects if...else use of statements

If ' is evaluated in parentheses, the declaration is really executed; otherwise, the declaration is skipped.
  
If two or more lines of code are executed, the curly braces {} must be used to specify what code belongs to the if declaration.
  
Other keyword extensions to the basic functionality of the If Declaration are provided by other options.
if (expression)
Statement1;
Else
Statement2;

Instance

<script language= ' JavaScript '
    <!--
    var VarA = 2 ;
    var varb = 5;

    if (VarA = 0)
      document.write ("VarA = 0");
  & nbsp else {
      if ((VarA * 2) >= Varb)
        document.write ("(VarA * 2) >= Varb");
      Else
        document.write (VarA * 2) < Varb ");
      document.write (Varb);
   }
   //-->
</script>

If else

if (statement) {
     ;  Code;
   }else (statement) {
      code;
   }

A specific case in which a If...else statement is logically stated.
  
If statements are satisfactory, their statements are executed.
  
else, the other statements were evaluated.
  
When the statement is to be true, the code is executed.

<script lanuguage= "JavaScript" >
<!--
var temp = 1;

if (temp = = True) {
document.write ("Statement is true");
} else{
document.write ("Statement is false");
}

-->
</script>

If ElseIf
<title>if...then...else...if</title>
<script type= "Text/javascript" >
var statecode = ' MO ';

if (statecode = = ' OR ') {
Taxpercentage = 3.5;
else if (statecode = = ' CA ') {
Taxpercentage = 5.0;
else if (statecode = = ' MO ') {
Taxpercentage = 1.0;
} else {
Taxpercentage = 2.0;
}

document.write (Taxpercentage);

</script>

<body>
</body>

Related Article

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.