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 use methods are:
(1) As a function's parameter, the function's parameters are not objects. (2) As the end point of the object prototype chain.
Object.getprototypeof (object.prototype)//null
2. Undefined means "missing value". This is where there should be a value, but not yet defined. Typical use methods are:
(1) The variable is declared. But when there is no value assigned. is equal to undefined. (2) The number of parameters that should be provided when calling a function is not provided. This number 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