In JavaScript, why is null = 0 false and null greater than = 0 true (my research) _ javascript tips-js tutorial

Source: Internet
Author: User
I have nothing to do today. I have studied the relationship between "null" and "0. I hope you will get something better after reading it. I hope you will also enjoy the benefits of writing code without stopping, writing JavaScript, and very little time for conceptual research. I am not busy today. I have studied the relationship between "null" and "0. I hope you will get some results after reading this article.

The Code is as follows:


Alert (null> = 0)


The Code is as follows:


What will pop up in the above Code? False? True? It is actually true. So why? Why is "null> = 0" true? If the value is null> = 0, it is converted to the numeric type. When performing a null> = 0 comparison, it is the answer obtained by comparing null <0. If a = B is false, if a = B is true, that is, if 0 <0 is false, that is, if null <0 is false, then null> 0 is true. So null> = 0 is true.


The Code is as follows:


Alert (null = 0)


What will pop up in the above Code? False? True? It is actually false. "Null = 0" is a special processing. It is not converted to a numeric type and not to a numeric value. However, if the left side is a numeric value on the right side of the string, it is converted. "Null" is an object (empty object without any attributes or methods ). "0" is a number. As mentioned above, "=" is not a conversion type, but a comparison. Therefore, it is false.

Why is "null = 0" false, but "null> = 0" true? This small problem is analyzed here. I also learned a lot in the analysis process. I think you will have some gains when looking at it again. All of the above are my opinions. If you cannot understand anything, you are welcome to join us in learning.

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.