The difference _javascript skills between undefined and "undefined" in JScript

Source: Internet
Author: User
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.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.