InterviewHubPRO
Section Overview
Q304

Question 304 of 521

Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

58%
JavaScript Internals (521 Qs)•Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

What is a void operator

The void operator evaluates the given expression and then returns undefined (i.e, without returning value). The syntax would be as below,

javascript
  void expression;
  void expression;

Let's display a message without any redirection or reload

javascript
  <a href="javascript:void(alert('Welcome to JS world'))">
    Click here to see a message
  </a>

Note: This operator is often used to obtain the undefined primitive value, using void(0). Also it can be used to call asynchronous functions without waiting for the result.