Js--if condition judgment

Source: Internet
Author: User

Now only special cases are mentioned:

1, a variable, such as N1=null

<script>        varnull;        Alert (N1); /* the value of the popup window is null */        if null) { /* If it is an if (N1) will not execute inside the function body *            /alert ("popup Window");        } </script>

2, a variable, such as N1, does not assign a value

<script>        var  N1;        Alert (N1); /* the value of the pop-up window is undefined */        if (typeof (n1) = = "undefined") {/* If it is an if (N1) or if (n1== "undefined") will not execute the inside function body *            /alert ("Popup Window" );        } </script>

3, a variable, such as n1,n1= ""

<script>        var n1 = "";        Alert (N1); /* the value of the popup window is empty (nothing is displayed, but the window is bounced) */        if (N1 = = "") { /* If it is an if (N1) will not execute inside the function body *            /alert ("popup Window");        } </script>

4, a variable, such as n1,n1= ""

<script>    var n1 = "   ";    Alert (N1); /* the value of the popup window is empty (nothing is displayed, but the window is bounced) */    if (N1) { /* If it is N1.trim (). length > 0 will not execute inside the function body *        /alert ("popup Window");    } </script>

5, a variable, such as N1,N1=0,N2 not assigned value

<script>        var n1 = 0;         var n2;         + N2); /* the value of the popup window is Nan */        if (IsNaN (n1 + n2)) { /* If an if (n1 + N2) will not execute inside the function body *            /alert ("popup Window");        } </script>

6, for the above situation, in addition to n1= "" assignment is a number of spaces this special case, others can be judged by the following code

if (!N1)

Note: Because of the above cases, direct write if (n1) or if (N1+N2) does not directly execute the code in the function body, so it is also possible to write this.

Js--if condition judgment

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.