First, the difference between null and undefined:
Executes typeof on declared but uninitialized and undeclared variables, returning "undefined".
Null represents an empty object pointer, and the typeof operation returns "Object".
Generally do not explicitly set the value of the variable to undefined, but null instead, for the variable that will save the object, you should explicitly let the variable hold a null value.
var//"undefined"null; alert (typeof//" Object "null//truebj =null//False
The following function detects if the object is empty:
/* * Detects if the object is an empty object (does not contain any readable properties). The * method detects both the properties of the object itself and the attributes inherited from the prototype (and therefore does not make hasownproperty). */function isEmpty (obj) {for (var in obj) { return false ; } return true ;};
Whether the empty object here is {} or null. Write a test case below.
var a == ' realwall '//false//trueconsole.log ( IsEmpty (null//true// Note No syntax error when parameter is null Oh, that is, although you cannot add a property to a NULL Null pointer object, you can use the for Statement
The following method determines whether an object is empty, detects only the properties of the object itself, and does not detect attributes inherited from the prototype.
/* * Detects if the object is an empty object (does not contain any readable properties). The * method only detects properties of the object itself and does not detect attributes inherited from the prototype. */function isownempty (obj) {for (var in obj) { if (Obj.hasownproperty (name)) { returnfalse; } } return true ;};
The difference between {} and null:
var a = {}; var NULL = ' realwall '// error here, B is a null pointer object and cannot be added directly as a normal object. B =// at this point A and B point to the same object. A.name, b.name are ' jam '
Determine if the JavaScript object is null or the property is empty