Undefined = null: Difference and link between the two. Page 1/3

Source: Internet
Author: User

It seems that I have also seen null = undefined, null! = Undefined.

Recently I 've looked at other people's program source code, and there are some such as if (x! = Undefined & x! = Null & x! = "") And so on, suddenly felt that the write is very wordy, I usually directly if (x) {} No matter whether it is null, undefined, or "", it is true that it is false in the condition judgment. Why should it be so arrogant? (However, if your x = 0 is also a valid value, you cannot use if (x) {} for condition determination)

To prove this redundancy, I also made the following tests:
Alert (x)
If (x = null ){
Alert ('failed ')

X is an uninitialized variable, that is, undefined.
Run the above Code: undefined and failed are successively displayed, indicating that x = null is qualified.

We can directly use alert (null = undefined) to find that true is returned.

This indicates that x = null | x = undefined or x! = Null & x! = Undefined is redundant!

Generally, you only need to judge null or undefined.

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.