JS string comparison "==" and "===" the difference

  Recent oil js course curriculum, after-school exercise proper way on a question similar to the one below, then called the comparison result of the judgment, the beginning looked knowledge of the Internet, this is not quite understand, vague personal feeling (of course I own food, it is normal), then a brief analysis of java object reference with vaguely remember, and will review recent knowledge, any errors will be corrected in a timely manner, of course, welcome to the treatise.

1. About js string comparison: "==" "===" column:

      Var a=”abc”;

      Var b=”abc”;

      Var c=new String(“abc”);

      Var d=new String(“abc”);

      1.a === b => true not create the same target object is a solid column, the object should be created to point to the default, it will point to the same value as long as

      2.a === c => false, c to create a new object, and the object point, with "===" comparison result to false (Similarly, a, b and d with "===" are is false)

      3.c === d => false for the same reasons 2, c, d point to two reference objects are not the same, are two new

     The following is a reprint source https://www.cnblogs.com/nelson-hu/p/7922731.html

2. The double equal sign ==: 

  (1) If the two values ​​are the same type, then compared three equal sign (===) of

  (2) If two different value types, there may be equal, need to be cast in the comparison according to the following rules:

    1) If a is null, a is undefined, then the equal

    2) If a string, a numerical value is then compared to the value after converting string

  

3. Third === No:

  (1) If the types are different, it will not equal

  (2) If two values ​​are, and the same value, equal; if at least one of which is a NaN, then unequal. (Determines whether a value is NaN, only use isNaN () to determine)

  (3) If the two are strings of characters for each position are the same, then equal to, or not equal.

  (4) If the two values ​​are true, or false, then equal

  (5) If both values ​​refer to the same object or function, then equal to, or not equal

  (6) If the two values ​​are null, or undefined, then equal

 Note: reproduced please indicate the source, blog content in addition to content outside reprint show are original, although written blog is a rookie, but please respect for others, respect for themselves, thank you.

Guess you like

Origin www.cnblogs.com/lydcp/p/12555341.html