Undefined==null caused by the difference and contact 1th/3 page _javascript Tips

Source: Internet
Author: User
Seems to have seen null==undefined,null!==undefined before, but also has not cared.

Recently looked at someone else's program source code, everywhere have some such as if (x!=undefined&&x!=null&&x!= ""), such as judgment, suddenly feel written very long-winded, I generally direct if (x) {} because no matter null, Undefined, "" in the conditional judgment is in fact false, why should it be so verbose? (Note that if your x==0 is also valid, you cannot use the if (x) {} to make conditional judgments)

In order to prove this superfluous, I also deliberately did the following tests:
var A;
Alert (x)
if (x==null) {
Alert (' failed ')
}

where x is an uninitialized variable, that is, undefined.
Run the above code: successively pop-up undefined and failed, indicating that the x==null is eligible.

We can directly alert (null==undefined) can actually find the return of true.

It all means to x==null| | X==undefined or x!=null&&x!=undefined and so on are purely superfluous!

Generally you just have to judge null or undefined one.
Current 1/3 page 123 Next read the full text

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.