JS in the 6 major types: Number,string,boolean,null,undefined,object, where null and undefined accounted for 2 seats, and their role is to represent the empty, In my usual work I have not found the difference between the two, then what is the difference between them?
It is mainly embodied in semantics:
NULL indicates that a value is defined and defined as a null value. Undefined indicates that the value is not defined at all and the value does not exist . In other words, setting a value of NULL is reasonable, and setting a value of undefined is unreasonable.
Note whether the value is null or undefined, the variable must be declared, otherwise it will be an error, which is different from the value of the Access property.
var A; var b == = = = = = undefined); // true null); // false Console.log (c); // Error = = = undefined); // true null); // false
When the property is accessed, the internal [[get]] method is called (see Uncle Tom's deep understanding of the JavaScript series), which returns undefined if no attributes are found on the prototype chain.
O.[[get]] (P)://if it is a property of its own, it returnsif(O.hasownproperty (P)) {returnO.P;} //Otherwise, continue to analyze the prototypevar__proto =O.[[prototype]];//If the prototype is null, return undefined//This is possible: top-level Object.prototype. [[[Prototype]] is nullif(__proto = = =NULL) { returnundefined;} //Otherwise, recursive invocation of the prototype chain [[Get]], find properties in the prototypes of each layer//until the prototype is nullreturn__proto. [[Get]] P
Back to our topic, so if you determine whether a value exists, then you should use obj.value = = = undefined without applying null.
In the usual cases:
1. The end point of the prototype chain is NULL
2. The variable declaration is not assigned a value of undefined
3. The attribute value that the object does not define is undefined
4. Returns undefined when the function has no return value
5. When calling a function, the missing parameter value is undefined
There are shortcomings, welcome to correct the exchange.
null and undefined in
JS