Void Keyword in ES6

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

void expression

Example

We have an example of the void keyword.

var a,b,c;
a = void (b = 10, c = 20);
console.log (‘a = ’ + a + ‘b = ’ + b + ‘c = ’ + c );

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.

<html>  
<head>   
</head>  
<body>  
    <center>  
        <h2>Hello ES6</h2>  
        <h3>Welcome to ES6</h3>  
        <h2>Click on the links to see the changes</h2>  
        <a href = "javascript:void(javascript:alert('hello world!!'))">  
            It is only a sample link. 
          </a>  
          <br/><br/> 
          <a href = "javascript:alert('Welcome to ES6');">Click here for an alert</a> 
    </center>  
</body>  
</html>

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.

void function welcome()
{
          var alert = function ()
{console.log(“Welcome to ES6”)};
alert();
}(); 

Output

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

Void Keyword in ES6

Related Topics

Array Destructuring in ES6

Array Destructuring in ES6 The term ‘Destructuring’ is defined as dividing the complicated data structure into easier modules. The Destructuring syntax helps to extract the small segments from an array and the objects....

3 minutes read.

String in ES6

String in ES6 The term string can be defined as an object used to represent the sequence of the characters. The string is widely used to store a text-based value like...

9 minutes read.

Decision-Making in ES6 | ECMAScript 6

Decision-Making in ECMAScript 6 The Decision-making structure or statements are used to determine one or more than one condition to be evaluated or tested. The Decision-making statement helps us to decide...

7 minutes read.

Functions in ES6 | ECMAScript 6

Functions in ECMAScript 6 In ECMAScript programming language, the term ‘function’ can be defined as a collection or group of input statements, used to perform particular computational calculations and generate the output...

9 minutes read.

Spread Operator in ES6

Spread Operator in ECMAScript 6 The term 'Spread Operator' can be defined as an operator that allows expending the array into separate elements. Three dots (…) isthe syntax of the Spread Operator.The Spread operator...

5 minutes read.

Types of Inheritance in ES6

Types of Inheritance The term inheritance can be divided into following three parts- Single-level InheritanceMultiple InheritanceMulti-level Inheritance Single-level Inheritance The single-level inheritance can be defined as an inheritance in which the child class can...

5 minutes read.

Dialog box in ES6

Dialog box in ES6 A dialog box can be defined as a regular type of window in the Graphical User Interface (GUI) of the operating system. It is also spelled as...

5 minutes read.

Immediately Invoked Function Expression ES6

Immediately Invoked Function Expression (IIFE) Immediately Invoked Function Expression (IIFE) is a JavaScript function used to ignore the variable hoisting from inside the code block. An IIFE is a function that runs...

3 minutes read.

Object in ES6

Object in ES6 The term object can be defined as an instance that contains the group of key-value pairs. We can modify it using the life cycle of an object in...

6 minutes read.

Environment Set up in ES6

Environment Set up in ES6 JavaScript is a portable language. It can execute on any browser or any host, and any operating system. Before the use of JavaScript, we need to...

5 minutes read.

Number in ES6

Number in ES6 In ES6, we have various methods and properties to implement numeric functions such as floating-point, integers, date, etc. The numbers in ES6 enable us to work with number...

7 minutes read.

Set in ES6

Set in ES6 A Set is a kind of object used to create a group of unique values. The values stored in a set can be string, literal, array, and integer....

6 minutes read.

Operators in ES6 | ECMAScript 6

Operators in ECMAScript 6 The term Operator is refers to a symbol that is used to instruct the computer system to perform a specific operation. The ECMAScript 2015 supports a rich set of operators....

11 minutes read.

Validation in ES6

Validation in ES6 The term validation can be defined as a mechanism to check the information given by the user is correct or not according to the requirements. If the data...

9 minutes read.

Animation in ES6

Animation in ES6 In JavaScript, the animation feature is used to manage the aspect that the CSS (Cascading Style Sheet) can’t. JavaScript provides various new elements that help us to construct...

8 minutes read.

Void Keyword in ES6

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...

2 minutes read.

Promises in ES6

Promises in ES6 A promise is used to represent some aspects that are finally fulfilled. It can also be resolved or discarded according to the operational output. In ES6, a promise...

8 minutes read.

Loops in ES6 | ECMAScript 6

Loops in ECMAScript 6 A Loop statement can be defined as a group of instructions that are always repeated. In the computer programming language, the loops help us to execute a collection of instructions...

8 minutes read.

Loop Control Statement in ES6

Loop Control Statement in ECMAScript 6 The loop control statements can be defined as a set of conditions that control the execution of the loop. It executes the loop until the condition becomes false....

6 minutes read.

Array in ES6

Array in ES6 The array can be defined as an object that is used to display the set of homogenous type of elements in ECMAScript 6. The array provides the facility to store...

5 minutes read.