About the relationship between 0,null,undefined,[],{},'''''''',false in JS

Comparison of 0 with some imaginary value:

0 and false

0==false
true

0 and '':

0==''
true 

0 and []:

0==[]
true 

0 given NaN:

0 == NaN
false

0与undefined

0==undefined
false

0 and null

0==null
false 

0 and {}

0=={}
false

''Comparison of empty value with some value

?
1
2
3
4
5
6
7
8
9
10
11
12
'' == false
true
'' ==undefined
false
'' == null
false
'' ==NaN
false
'' ==[]
true
'' =={}
false

 Null is equal to false,[]

?
1
undefined == null ==> true

I don't know what the comparison of these values ​​is. Whether these values ​​are equal together can be used in some js

Let's add the relationship between undefined, null, empty string, false, true in js.

Because I have seen in other books that undefined, null, and empty strings can be used as false in the if statement, I always thought that undefined, null, empty strings, and false are equal;

Some time ago, I accidentally found that undefined==null when writing code; but these two are not equal to null characters and false; to understand the relationship between them, I interviewed on the browser again; the following are the experimental results

false为boolean型;‘'为字符串型;当不考虑他们的数据类型时两者相等;当考虑数据类型时两者不相等

实验发现null的数据类型为object ;无论是否考虑数据类型空字符和空都不相等

当不考虑字符类型时发现undefined等于null 当考虑字符类型时undefined不等于空

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325769065&siteId=291194637