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

Page Redirect in ES6

Page Redirect in ES6 The term redirect can be defined as a process to send the user and search engine on a specified URL from the original page. “The page redirection is...

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

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.

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.

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.

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 Methods in ES6

Array Methods in ES 6 ES 6 introduced the various new methods such as Array,from(), Array,of(). Here, we have the various array methods used in JavaScript, they are given below in the table...

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

Class in ES6

Class in ES6: The Class is a basic term in object-oriented programming (OOPs). A class helps to determine the prototype for modeling in real-world objects. It is used to formulate...

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

Boolean in ES6

Boolean in ES6 In ES6, the Boolean object is used to show two values either it may be true or false. In JavaScript, we can use the Boolean object as a...

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

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.

Generator in ES6 | ECMAScript 6

ECMAScript 6 recommends a new way of working with iterators and functions. The way is named as generator or generator function. The ES 6 generator is a distinct type of function that...

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.

Features of ES6 | ECMAScript 6

The ES6 or ECMAScript 2015 came with various exiting and new features. These features make it a more robust and updated programming language than ES5. Some of these new promising features are Const...

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

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.

Module in ES6

Module in ES6 In ES6, the modules can be defined as a small chunk of program code stored in a file. The modules are used to modularize the source code with...

6 minutes read.