JS and so the double equal sign and a full comparison mechanism

JavaScript in the "==" and "===" usage:

  Equal "==" Analyzing implicit conversion mechanism

 

    1 determines whether or NaN (not a Number is the number of non-numeric data in a computer science type indicates an undefined value or not represented)

    Determining whether the number on both sides of the equation NaN, if there is, it is determined that all false

    2. Is there a Boolean value

      2.1 while for the Boolean type, while for the expression

        Boolean expressions to determine and compare Boolean

      2.2 while for the Number type, while for the Boolean type

        The Boolean type to Number, false = 0, true = 1, then compared

    3.null和undefined

      Nul encountered or undefined, data type conversion is not performed, the comparison between the two, returns true

    4. There is a string side is

       4.1 is also the other side of String

        Directly comparing the value of both sides of the equation

       4.2 on the other side of type Number

        String to compare type Number

      4.3 the other side is a Boolean

        Type String while converting a Boolean type Number and then compared (false = 0, true = 1)

      4.4 the other side is an array of objects or

        You will need to call toString () method or valueOf () method of converting a simple type, and then compare

        ValueOf call will be limited when the object into simple types () method, if they can be compared directly with a simple type, no longer calls the toString () method, otherwise it calls the toString () method

  "===": Comparison of the data type value +

      It must be completely equal only to true

 

Excerpt: https: //blog.csdn.net/qq_37530031/article/details/78317823 

 

Guess you like

Origin www.cnblogs.com/myBlog-ahao/p/11081714.html