First of all, the difference between null and undefined:
Performs typeof on declared but uninitialized and undeclared variables, and returns "undefined".
Null represents an empty object pointer, and the typeof operation returns "Object".
It is generally not explicit to set the value of the variable to undefined, but null instead, for the variable that will save the object, make it clear that the variable holds the null value.
var bj;
Alert (BJ); "Undefined"
bj = null;
Alert (typeof BJ); "Object"
alert (BJ = = null);//true
bj = {};
Alert (BJ = = null); False
The following two functions are Deng Shi brother to me, thank you ah.
* * Detects if an 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 stereotype (and therefore does not make hasownproperty).
*/
function IsEmpty (obj)
{for
(var name in obj)
{return
false;
}
return true;
};
The empty object, in the end, is {} or null. I wrote a test case.
var a = {};
A.name = ' Realwall ';
Console.log (IsEmpty (a)); False
Console.log (IsEmpty ({})),//true
console.log (IsEmpty (null)),//true
//Note No syntax error when parameter is null Oh, That is, you cannot add an attribute to a NULL Null pointer object, but you can use the for in statement
?
* * Detects if an object is an empty object (does not contain any readable properties). The
* method detects only the properties of the object itself and does not detect inherited properties from the stereotype.
*/
function isownempty (obj)
{for
(var name in obj)
{
if (Obj.hasownproperty (name))
{return
false;
}
}
return true;
};
{} differs from null:
This thing is very important.
var a = {};
var b = null;
A.name = ' Realwall ';
B.name = ' Jim '; This will be an error, B is a null pointer object, you cannot add attributes directly like normal objects.
B = A;
B.name = ' Jim '; A and B point to the same object at this point. A.name, b.name are ' jam '