null and undefined in JS

Source: Internet
Author: User

Reference Link: http://blog.csdn.net/qq_26676207/article/details/53100912

Http://www.ruanyifeng.com/blog/2014/03/undefined-vs-null.html

Http://www.tuicool.com/articles/b6vqmy

About when Null appears when undefined:

So Answer:

The variable definition is undefined when it is not assigned, or it is a variable defined as an unassigned variable or typeof;

null, which represents an empty object, is the hour of the prototype chain, and when a space is freed, the variable is assigned null, and the garbage collection mechanism recycles it, typeof Null is an object;

typeof returns a string of six possible types: "number", "string", "boolean", "object", "function", "undefined";

Undefined values and definitions unassigned for Undefined,null is a special Object,nan is a special number.

var a1;
var A2 = true;
var a3 = 1;
var a4 = "Hello";
var A5 = new Object ();
var a6 = null;
var a7 = NaN;
var a8 = undefined;
Alert (typeof a); Show "undefined"
Alert (typeof a1); Show "undefined"
Alert (typeof a2); Show "boolean"
Alert (typeof a3); Show "number"
Alert (typeof a4); Show "string"
Alert (typeof a5); Show "object"
Alert (typeof a6); Show "object"
Alert (typeof a7); Show "number"
Alert (typeof a8); Show "undefined"

The = = operator considers the undefined value equivalent to Null.

Null represents a definite already known value, which is an empty object

Null means "no object", that is, there should be no value at All. Typical uses are:

(1) as a function parameter, the parameter of the function is not an object.

(2) As the end point of the object prototype Chain.

Object.getPrototypeOf(Object.prototype)// null




从逻辑角度上来讲,null值表示一个空指针对象

null and undefined in JS

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.