Void Keyword in ES6

In ES6, the void keyword is referred to as a function return type, but it does not return any value. It classifies the expression and returns the undefined value. In JavaScript, the void keyword is also used as a unary operator, and it is shown before the single operand. The void operator is widely used to access the undefined primitive value.

Syntax

Example

We have an example of the void keyword.

Output

After the execution of the above code, we got the following output:

Void Keyword in ES6

Void keyword and JavaScript URI

The term URI can be defined as a JavaScript library that helps us to work with URLs. The JavaScript URI is often used as a syntax within an HTML page. If the browser peruses the URI, then it accesses the URI code. It also changes the page data with the returned value.

The void operator always returns the missing value.

Example

Here, we have an example to understand the above concept.

Output

After the execution of above example, we got the following example:

Void Keyword in ES6

If we click on the first link, then we will get nothing. But if we click on the next link, then we will get the following alert message as an output.

Void Keyword in ES6

Void Keyword and Immediately Invoked Function Expression (IIFE)

The void keyword with IIFE refers to as an expression instead of the declaration.

Example

We have an example given below to understand the following concept.

Output

We got the following output, after the execution of the above code.

Void Keyword in ES6

Pin It on Pinterest

Share This