The difference between null and undefined

Source: Internet
Author: User

Undefined represents the value when the variable is declared but not initialized.

Null means that the object is ready to be saved, and the value of the object is not actually saved. From a logical point of view, a null value represents an empty object pointer.

There are 5 basic types of JavaScript (ECMAScript Standard): Undefined, Null, Boolean, number, String, and a complex type object. You can see that null and undefined belong to different types, uninitialized defined values are detected by typeof as "undefined" (strings), and null values are detected by TypeOf as "Object" (String).

It is not recommended to explicitly set a variable to undefined at any time, but if the variable that holds the object does not actually hold the object, it should be set to null.

In fact, the undefined value is derived from a null value, and the ECMAScript standard specifies that the test for equality should return true, that is,

alert (null==undefined); True

The difference between null and undefined

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.