Explain the use of void statements in JavaScript basics

Source: Internet
Author: User

Void is an important keyword in JavaScript that can be used as a unary operator before its single operand, and may be of any type.

This operator specifies an expression that does not require a return value to be evaluated. Its syntax may be one of the following:

 
 

Or

void (func ())
Javascript:void (func ())
//-->
</script>
 
 

Example 1:

The most common use of this operation is the client-side Javascript:url, which evaluates the expression that calculates its boundary effect, without displaying the browser that evaluates the value of an expression.

Here, the expression alert (' Warning!!! ') evaluates the evaluation, but is not loaded back into the current document:

 
 


Example 2:

Another example of the link below does nothing, because the expression "0" has no effect in JavaScript. Here, the expression "0" is evaluated, but it is not loaded back into the current document:

 
 


Example 3:

Another use of void is to intentionally produce an indeterminate value, as follows:

 
 

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.