The meaning of void 0 in JavaScript and the difference between undefine and void 0

Source: Internet
Author: User
Undefined is a global property that indicates that no assignment has been defined or defined.  Void is a unary operator that returns undefined no matter what parameters are passed in.  The void operator is defined in ECMAScript V1, and undefined is defined in ECMAScript v5. We know that undefined is not a reserved word for JavaScript, so we can use undefined as the variable name. At this point, the undefined we define will affect the use of undefined as a judgment place . Look at the following example: tested mainstream browsers ie7-ie11, Opera, Firefox, Safati, Chrome
undefined=123;   // IE7, IE8 is 123, the rest: Ie9-ie11, opera, Firefox, Safati, Chrome are undefined alert (void 0); // Ie7-ie11, Opera, Firefox, Safati, Chrome are all undefined
Finally, a summary: using void 0 instead of undefined is for compatibility and for preventing code from being non-canonical (self-modifying the value of undefined).

The meaning of void 0 in JavaScript and the difference between undefine and void 0

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.