Null and undefined in js

Source: Internet
Author: User

Null and undefined in js

Null is a keyword in js, indicating a null value. Null can be considered as a special value of the object type. If the value of an object is null, it indicates that this object is not a valid object. Here, null and 0 are not the same thing. In c ++, null is usually defined as 0, but not in js.

Undefined is not a js keyword. It is a Global variable, that is, an attribute of Global. In the following three cases, undefined is returned:

1. An undefined variable is used;

2. variables defined but not assigned values are used;

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


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 indicate the value is missing, so here they are equivalent. But not completely 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.