Home > Web Front-end > JS Tutorial > Why is null==0 false in JavaScript and null greater than=0 is true (personal research)_javascript skills

Why is null==0 false in JavaScript and null greater than=0 is true (personal research)_javascript skills

WBOY
Release: 2016-05-16 17:22:27
Original
1174 people have browsed it

In life, we are constantly writing code and writing JavaScript, and we rarely have time to conduct conceptual research. As for me, I have nothing to do today, so I studied the relationship between "null" and "0". I hope everyone can gain something from reading it.

Copy code The code is as follows:

alert(null>=0)

Copy code The code is as follows:

What will pop up with the above code? False? True? Actually it is true. So why? Why is "null>=0" true? When null>=0, it is forced to a numeric type. When comparing null>=0, it is the answer obtained by comparing null<0. If a=b is false, if a=b is true, that is, 0<0 is false, that is, null<0 is false, then null>0 is true. So null>=0 is true.

Copy code The code is as follows:

alert(null==0 )

What will pop up in the above code? False? True? Actually it is false. "null==0" is treated specially and will not be converted to a numeric type or a numerical value. However, if the left side is a string and the right side is a numerical value, it will be converted. "null" is an object (empty object, without any properties and methods). And "0" is a number. As mentioned before, "==" does not convert types, but only compares. Therefore, it is false.

Why is "null==0" false, but "null>=0" is true? This is the end of the analysis of this little problem. I also learned a lot during the analysis process, and I think everyone will gain something when they read it again. The above are all personal opinions. If there is anything you don’t understand well, you are welcome to raise it and let us all learn together.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template