"Reprint" returns undefined using operator void in JavaScript

Source: Internet
Author: User

Use operator void to return undefined in JavaScript Technology

Maybe yes posted on 2014-12-30 18:45

Original link: http://blog.lmlphp.com/archives/53 from: lmlphp backyard

When you return undefined in a JavaScript function and execute an expression, you can use the Void keyword. The most familiar use of void is generally in the href attribute of the link, you can block the default behavior of the <a> tag. Take a look at the following code snippet:

<script>function (t) {return o?t (): void I.push (t)}</script>

Using void in JavaScript to manipulate the return value of any one expression is undefined. There are other ways to get undefined in a function, see the following example, a snippet from the LMLJS framework:

<script> (function (Win, doc, undf) {}) (window, document);</script>

In the anonymous function above, one is defined when defining the parameter, and the default value of the parameter not passed is undefined. about how to get undefined in JavaScript? Direct use of undefined is not rigorous, because "undefined" is not a reserved word in JavaScript and can be assigned a value. Many editors highlight undefined when highlighting JavaScript code, which makes it easy for programmers to misunderstand. Therefore, the best way to return the undefined type value in JS is to use void 0.

Read (25) reviews (0) View comments


"Reprint" returns undefined using operator void in JavaScript

Related Article

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.