Used in JScript to represent undefined undefinedWhat exactly does an identifier mean undefined? IT and "undefined" What are the differences and connections (including "included")? Why sometimes can use undefined to compare with variable, and sometimes not?
The difference between underfined and "undefined" can be seen at a glance. In general, we consider undefined to be a "keyword" provided by JScript, while "undefined" is nothing short of a string, but the contents of quotes are long and undefined the same. Although the difference between undefined and "undefined" is very obvious, they are closely related.
Carefully read the JScript manual, in fact this underfined is a "defined" global value, rather than its literal meaning expressed in undefined. Let's look at the following code example, which is interesting:
<script language= "JavaScript">
alert (undefined);
alert (variable);
</Script>
the results of the execution are:
Let's modify the code slightly and add a typeof to see:
<script language= "JavaScript">
Alert (typeof undefined);
Alert (typeof variable);
</Script>
what should be the result? Show "object" and "undefined" ? Of course not, two alert calls will display the "undefined" .
so undefined is a constant defined by the script engine that exists after the script engine has been initialized. Its actual effect is to use
to represent the uninitialized state (uninitialized) of a defined variable, such as Var I, at which point the value of this I is undefined , and I is a real define, but not initialized. At this point we can write an expression to judge I, such as if (i = = undefined ). If a variable that has never been in the code is used, the undefined concept is not to undefined , but rather to state that the variable was not enlisted in the context of the script engine at all. Using a statement like if (abc = = undefined ), you get a second error hint similar to the one in the previous illustration.
In practice, if you use TypeOf to determine whether a variable is undefined, you can be fully compatible with
undefined (undefined) and
uninitialized ( Uninitialized) Two kinds of cases, just a lot of times I don't like to use if (typeof xxx = = ' undefined ' ) Because literal's strings are easily misspelled, they are unprofessional in the sense of being accustomed to a strongly typed language.