JavaScript Void Keyword - Java Script

What is JavaScript Void Keyword?

In JavaScript, Void is a significant keyword which is used as an unary operator that can be placed before its single operand, which can be of any type.

The Void operator facilitates to evaluate a JavaScript expression without returning a value.


We can use the Void syntax in either of the following two ways:

Example 1:

Void operator is frequently used in a client-side JavaScript: URL, where it letsone to evaluate an expression for its side-effects without the browser (Chrome, Opera, Safari,IE and Firefox) displaying the value of the evaluated expression.

Below is the expression alert ('Warning!!!') which is evaluated but it will not be displayed to the visitor.


Example 2:

Take a glance at the below example. Expression "0" has no impact when used in JavaScript. Here'show the expression "0" is evaluated, which will not be displayed in the page when viewed.


Example 3:

Further use of void is to intentionallyproduce the undefined value as below.


All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

Java Script Topics