This article describes how to obtain the pure undefined method in JavaScript. For more information, see section 1. Why do you want to obtain undefined?
Because undefined is not a reserved word in javascript, it can be assigned as a variable. If undefined is used to detect a variable in the future, the value of undefined is inaccurate;
Example:
Var undefined = 10; function sum (a, B) {if (a === undefined | B === undefined) {console. log ("Incorrect Parameter");} 18101130357 return a + B ;}
Sum ()-> If the parameter is correct, the console outputs "parameter error ";
At this time, in order to be compatible with all browsers, we need to obtain a pure undefinde
2. How to obtain pure undefined?
1) void (0 ):
The ECMAScript 262 specification is described as follows:
The void OperatorThe production UnaryExpression : void UnaryExpression is evaluated as follows:Let expr be the result of evaluating UnaryExpression.Call GetValue(expr).Return undefined.
In short, remember that no matter what the expression after void is, the void operator will return undefined.
2) input a parameter that is assigned a value.
[Case]
Function (_ undefined) {// The value of _ undefined is not assigned to the function body. The value of _ undefined is undefined. You can use _ undefined in this function}
3) unassigned variables
For example, var num // The truth is the same as 2 ).
Do not get bored with familiar things, make progress every day; Do not fear unfamiliar things, learn a little every day;
PS: js determines the undefined type
If (reValue = undefined) {alert ("undefined");} found that the judgment could not be found, and finally found the information to use the typeof method: if (typeof (reValue) = "undefined") {alert ("undefined ");}
Typeof returns a string, which may be "number", "string", "boolean", "object", "function", or "undefined"