Web page effects Null object detailed
Null
This is an object, but is empty. Because it is an object, typeof null returns ' object '.
Null is a JavaScript reserved keyword.
Null is automatically converted to 0 when it participates in numeric operations, so the following expression evaluates to the correct value:
Expression: 123 + null result value: 123
Expression: 123 * Null result value: 0
The following are not the correct methods:
var exp = null;
if (exp = null)
{
Alert ("is null");
}
When exp is undefined, it will also get the same result as NULL, although null and undefined are different. Note: This method can be used to determine both null and undefined.
var exp = null;
if (!EXP)
{
Alert ("is null");
}
If exp is undefined, or the number zero, or false, the result will be the same as NULL, although NULL is not the same as the two. Note: This method can be used to determine both null, undefined, number 0, and false.
var exp = null;
if (typeof exp = "NULL")
{
Alert ("is null");
}
For backward compatibility, when EXP is null, typeof null always returns object, so this cannot be judged.
var exp = null;
if (IsNull (exp))
{
Alert ("is null");
}
There is IsNull this function in VBScript, but not in JavaScript.
The following are the correct methods:
var exp = null;
if (!exp && typeof exp!= "undefined" && exp!= 0)
{
Alert ("is null");
}
typeof exp!= "undefined" excludes undefined;
Exp!= 0 excludes the number zero and false.
The simpler and the right way:
var exp = null;
if (exp = = NULL)
{
Alert ("is null");
}