How to use void keyword in JavaScript

In this article we will discuss about how to use void keyword in JavaScript.
  • 2768

In JavaScript we can use void keywords in many ways. Basically in JavaScript it is an unary operator which will be appear before its single operands. This operator defines an expression which will be evaluated without returning a value. It is most commonly used for client side JavaScript like URL where it will allow us to estimate an expression for its side effects without the browser displaying value of the estimated expression.

JavaScript Code:



    <script type="text/javascript">







        Click the following, This won't react at all...</p>

    <a href="javascript:void(alert('megha'))">Click me!</a>






In the following example the expression alert('megha') will be evaluated but it will not loaded back into the current document:

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2020 DotNetHeaven. All rights reserved.