Null special conversion

null special conversion, ask for advice

+null        // 0
null == 0    // false
null > 0     // false
null < 0     // false
null >= 0    // true

!!null         // false
null == false  // false
null == true   // false
null >= false  // true
Apr.12,2022

you asked yesterday, and I'll answer again.

    The
  1. + operator, if only on the right, is tantamount to calling the Nunber function.
  2. = = operator, null is only equal to null and undefined, and the rest are not equal.
  3. ! Cast to a Boolean value. In JavaScript, undefined,null,false,+0,-0,NaN,'' can be cast to false.

uses the < operator. If the side of the comparison is not a number, the Number function is called and converted to a number;

Number ({valueOf:1}) returns 1
Number (null) returns 0
Number (undefined) returns NaN
Number (false) returns 0
Number ([]) returns 0
Number ('') returns 0

so [] > false = > false,
[] > null = > false
[] > undefined = > false
[] >'= > false

  1. null > 0, null < 0. In this case, null will be converted to a number. Number (null) is 0, 0 is not greater than 0, nor less than 0. 0. Null > 0 returns true, null > 0. 1 returns false, obviously 0 >-1, 0 < 0. 1;
  2. null > false, which is equivalent to Number (null) > Number (false), 0 > 0 is not valid, so the result is false.
  3. In
  4. JavaScript, the result of a < = b is by inverting the result of (b from what we are used to thinking).

because null < 0 is false, the result of null > = false is true.


null will only be equal to undefined, that is, if null==undefined is true, all < > will be false > = < = this is the opposite of < >. You can take a look at
, which you don't know, and there is an explanation in javascript

.
Menu