Why Null==0 is false in JavaScript and NULL is greater than =0 to true (personal research) _javascript tips

Source: Internet
Author: User
Tags numeric value
In our lives we keep writing code, writing JavaScript, and have 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.
Copy Code code as follows:

Alert (null>=0)

Copy Code code as follows:

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.

Copy Code code as follows:

Alert (null==0)

What does the above code pop up? False? True? is actually false. "Null==0" is a special treatment, does not convert to a numeric type, does not translate to a numeric value, but if the left 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.
Related Article

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.