Why Null==0 is false in JavaScript and null>=0 to True

Source: Internet
Author: User
Tags comparison numeric numeric value


At work we are constantly writing code, writing JavaScript, very little time for conceptual research. I have nothing to do today, I studied the relationship between "null" and "0". I hope you have seen the end of the harvest.

Alert (null>=0)


What does the above code pop up? False? True? is actually true. So why is it? Why is "Null>=0" true? When Null>=0, a strong switch to a numeric type. When making a null>=0 comparison, it is the answer that is obtained by comparing null<0, and if A=b is false, if a=b is true, that is, 0<0 is false, or null<0 is false, then null>0 is true. So null>=0 is true.

Alert (null==0)


What does the code of the face pop up? False? True? is actually false. Null==0 "is a special treatment that does not turn into a numeric type and does not convert to a numeric value, but if the left side is a string to the right, the value is converted. "NULL" is an object (empty object with no properties and methods). and "0" is a number. Previously said "= =" does not convert the type, just comparison. So, false.

Why "Null==0" is false, but "null>=0" is true? This little problem is analyzed here. In the process of analysis I also learned a lot of things, I think we can see when there is a certain harvest it. Above all is the personal opinion, if has any understanding not to be in place, welcome to propose, everybody studies together ha.

Attach some reference

false false Td> Td>
= 0 ' 0 ' [0] [] {} ' NULL [NULL] undefined NaN [NaN] ' A ' Infinity 1 ' 1 ' [1]
0 true true true true false true false true false false false false false false false
' 0 ' true true true false false Span class= "false" >false false false false false false false false false false false
[0] true true false false false false false false false false false false false false false false
[] true false false false false true false false false false false false false false false false
{} false false false false false false false false false false false false false false false false
' true false false true false true false true false false false false false false false false
null false false false false false false true False true false false false false false false false
[null] true false false false false true false false false false false false false false false
undefined false false false false false false true false true false Span class= "false" >false false false false false false
NaN false false false false false false false false false false false false false false false false
[NaN] false false false false false false false false false false false false false false false false
' A ' false false false false false false false false false false false true false false false false
Infinity false false false false false false false false false false false false true false false false
1 false false false false false false false false false false false false true true true
' 1 ' false false false false false false false false false false false false false true true true
[1] false false false false false false false false false false false false false true true false
false false Td> Td>
= = 0 ' 0 ' [0] [] {} ' NULL [NULL] undefined NaN [NaN] ' A ' Infinity 1 ' 1 ' [1]
0 true false false false false false false false false false false false false false false false
' 0 ' false true false false false false false false false false false false false false false
[0] false false false false false false false false false false false false false false false false
[] false false false false false false false false false false false false false false false false
{} false false false false false false false false false false false false false false false false
' false false false false false true false false false false false false false false false false
null false false false false false false true False false false false false false false false false
[null] false false false false false false false false false false false false false false false false
undefined false false false false false false false false true false Span class= "false" >false false false false false false
NaN false false false false false false false false false false false false false false false false
[NaN] false false false false false false false false false false false false false false false false
' A ' false false false false false false false false false false false true false false false false
Infinity false false false false false false false false false false false false true false false false
1 false false false false false false false false false false false false true false false
' 1 ' false false false false false false false false false false false false false false true false
[1] false false false false false false false false false false false false false false false false
" ' Td> "
+ 0 ' 0 ' [0] [] {} ' NULL [NULL] undefined NaN [NaN] ' A ' Infinity 1 ' 1 ' [1]
0 0 ' ' 0 ' ' 0{} ' ' 0 ' 0 ' 0 ' nan nan ' 0NaN ' ' 0a ' infinity 1
' 0 ' ' ' 0 ' ' 0{} ' ' 0 ' ' 0undefined ' ' 0NaN ' ' 0a ' ' ' '
[0] " ' 0 ' ' 0{} ' ' 0 ' ' 0undefined ' ' 0NaN ' ' 0a ' ' ' '
[] ' 0 ' ' 0 ' ' 0 ' " ' {} ' Span class= "string" " ' null ' " ' NaN ' ' NaN ' ' a ' ' Infinity ' ' 1 ' ' 1 '
{} ' {}0 ' ' {}0 ' ' {}0 ' ' {} ' ' {} ' ' {} ' ' {}null ' ' {}undefined ' ' {}nan ' ' {}nan ' ' {}a ' ' {}infinity ' ' {}1 '
' ' 0 ' ' 0 ' ' 0 ' " ' {} ' Span class= "string" " ' null ' " ' NaN ' ' NaN ' ' a ' ' Infinity ' ' 1 ' ' 1 '
null 0 ' null0 ' ' null0 ' ' null ' ' null{} ' /span> ' null ' 0 ' null ' nan nan ' Nullnan ' ' nulla ' infinity 1 ' null1 '
[null] 0 ' ' 0 ' ' 0 ' " ' {} ' ' null ' ' undefined ' ' NaN ' Span class= "string" > ' NaN ' ' a ' ' 1 ' ' 1 ' ' 1 '
undefined nan ' undefined0 ' ' undefined0 ' ' undefined ' Span class= "string" > ' undefined{} ' ' undefined ' nan ' undefined ' nan nan ' Undefinednan ' ' Undefineda ' nan nan ' undefined1 ' ' undefined1 '
NaN nan ' NaN0 ' ' NaN0 ' ' NaN ' ' nan{} ' ' NaN ' nan ' NaN ' nan nan Span class= "string" > ' Nannan ' ' NaNa ' nan nan ' NaN1 ' ' NaN1 '
[NaN] ' NaN0 ' ' NaN0 ' ' NaN0 ' ' NaN ' ' nan{} ' ' NaN ' ' nannull ' ' NaN ' ' nanundefined ' " Nannan ' ' Nannan ' ' NaNa ' ' naninfinity ' ' NaN1 ' ' NaN1 ' ' NaN1 '
' A ' ' A0 ' ' A0 ' ' A0 ' ' a ' ' a{} ' ' a ' ' anull ' ' a ' ' aundefined ' ' Anan ' ' Anan ' ' AA ' ' ainfinity ' ' A1 ' ' A1 ' ' A1 '
Infinity infinity ' Infinity0 ' /td> ' Infinity0 ' ' Infinity ' ' infinity{} ' ' Infinity ' infinity ' Infinity ' nan nan ' Infinitynan ' ' Infinitya ' infinity infinity ' Infinity1 ' ' Infinity1 '
1 1 " ' ' 1 ' ' 1{} ' ' 1 ' 1 ' 1 ' nan nan ' 1NaN ' ' 1a ' infinity 2 ' one ' ' one '
' 1 ' " "" ' 1 ' ' 1{} ' ' 1 ' ' 1undefined ' ' 1NaN ' ' 1a ' " " ' one '
[1] ' ' ' ' 1 ' ' 1{} ' ' 1 ' ' 1undefined ' ' 1NaN ' ' 1a ' " " ' one '
* 0 ' 0 ' [0] [] {} ' NULL [NULL] undefined NaN [NaN] ' A ' Infinity 1 ' 1 ' [1]
0 0 0 0 0 nan 0 0 0 nan nan nan nan nan 0 0 0
' 0 ' 0 0 0 0 nan 0 0 0 Span class= "number" >nan nan nan nan nan 0 0
[0] 0 0 0 0 nan 0 0 0 Span class= "number" >nan nan nan nan nan 0 0
[] 0 0 0 0 nan 0 0 0 Span class= "number" >nan nan nan nan nan 0 0
{} nan nan nan nan nan Span class= "number" >nan nan nan nan nan nan nan nan nan nan
' 0 0
null 0 0 0 0 nan 0 0 0 Span class= "number" >nan nan nan nan nan 0 0
[null] 0 0 0 0 nan 0 0 0 Span class= "number" >nan nan nan nan nan 0 0
undefined nan nan nan nan nan nan nan nan nan nan nan nan Span class= "number" >nan nan nan
NaN nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan
[NaN] nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan
' A ' nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan nan
Infinity nan nan nan nan nan nan nan nan nan nan nan nan infinity infinity infinity infinity
1 0 0 0 0 nan 0 0 0 nan nan nan nan infinity 1 1 1
' 1 ' 0 0 0 0 nan 0 0 0 Span class= "number" >nan nan nan nan infinity 1 1 1
[1] 0 0 0 0 NaN 0 0 0 NaN NaN NaN NaN Infinity 1 1 1

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.