null and undefined in JS

Source: Internet
Author: User

Null is a keyword in JS that represents a null value. Null can be thought of as a special value of type object, if the value of an object is null, indicating that the object is not a valid object. Null and 0 Here are not the same thing, in C + + The NULL is usually defined as 0, but not in JS.

Undefined is not a JS keyword, it is a global variable, that is, a property of global, 3 cases will return undefined:

1. An undefined variable is used;

2. A variable that has been defined but not assigned is used;

3. An object attribute is used, but the property does not exist or is assigned;


Although undefined and null are different, running the following code returns TRUE.

alert (undefined==null);

var v= ""; alert (v.a==null); alert (v.a=undefined);

This is because undefined and null represent worth missing, so here they are equivalent. But not exactly equal, the following code returns false.

alert (nudefined==null);






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.