Differences between undefined and "undefined" In JScript _ javascript skills
Source: Internet
Author: User
Differences between undefined and & quot; undefined & quot; In JScript, the undefined identifier is used to indicate the undefined identifier. What does it mean? What is the difference and connection between it and "undefined" (including? Why can't I use undefined to compare variables sometimes?
The difference between underfined and "undefined" can be seen at a glance. In general, we think that undefined is a "keyword" provided by JScript, but "undefined" is a string without any suspense, the content in the quotation marks is just like undefined. The difference between undefined and "undefined" is obvious, but they are closely related.
Read the JScript manual carefully. In fact, underfined is a "defined" Global value, rather than its literal meaning. The following code example is interesting:
< Script Language = "Javascript" >
Alert (undefined );
Alert (variable );
Script>
The execution result is:
Let's slightly modify the above Code and add a typeof call to look at it:<ScriptLanguage= "Javascript">
Alert (typeof undefined );
Alert (typeof variable );
Script>
What is the result? Show "object" and "undefined? Of course not. Both alert calls will display "undefined ".
Therefore, undefined is a constant defined by the script engine. It exists after the Script Engine Initialization is complete. Its practical function is to use
To indicate the uninitialized status (uninitialized) of a defined variable)For example, var I;, the value of this I is undefined, and I is actually define, but it is not initialized. In this case, we can write such an expression to judge I, for example, if (I = undefined ). If variables that have never been used in the Code are used, the undefined concept is not initialized as described by undefined, the variable is not registered in the context of the script engine. If (abc = undefined) statements are used, the second error message is displayed.
In actual use, if typeof is used to determine whether the variable is undefined, it is completely compatible.
Undefined)And
Uninitialized)In either case, I do not like to use if (typeof xxx = 'undefined') because the literal string is prone to spelling errors, it is not professional in terms of the strong language that you are used.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.