An analysis of the difference between undefined and null
Similarities:
1, undefined, and null are the basic data types of JavaScript. In fact, there is not much difference between the two.
Defined:
var A=undefined;var a=null;null==undefined;//true
2, NULL is an object that represents "none", and a value of 0;undefined is a primitive value that represents "none", and a value of Nan when converted to a number.
Number (undefined)//nan5 + Undefined//nan
and for NULL
Number (NULL)//+ null//5
difference 1, 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
2. Undefined means "missing value", that is, there should be a value here, but there is no definition. Typical uses are:
(1) The variable is declared, but when it is not assigned, it is equal to undefined. (2) when calling a function, the argument that should be supplied is not provided, which equals undefined. (3) The object does not have an assigned property, and the value of this property is undefined. (4) When the function does not return a value, undefined is returned by default.
Example
var a;a;//undefinedfunction f (x) {console.log (x);} f (x);//undefinedvar obj=new Object (); Obj.name;//undefinedvar x=f (); x;//undefined
JavaScript advanced Programming--an analysis of the difference between undefined and null