Javascript Void Keyword

Javascript Void Keyword is used in a function signature to indicate that the function does not return any value. 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.

The void keyword is used in a function signature to indicate that the function does not return any value. It takes an expression of any type as its operand and returns undefined. The void(0) function actually returns null and works wonderfully by cancelling the page load.

Javascript Void Keyword Example 1

<html>
<head>
<title>Javascript Void Keyword Example</title>
</head>
<body>
<form name="myform">
<a href="javascript:void(alert('You ckicked on this hyperlink!'))"/>Click Here!</a>
</form>
</body>
</html>

Javascript Void Keyword Example 2

<html>
<head>
<title>Javascript Void Keyword Example</title>
</head>
<body>
<form name="myform">
<a href="javascript:void(0)">Click Here!</a>
</form>
</body>
</html>

Javascript Void Keyword Example 3

<html>
<head>
<title>Javascript Void Keyword Example</title>
<SCRIPT LANGUAGE="JavaScript">
function generateVal() {
   var num1, num2, num3;
   num1 = void (num2 = 15, num3 = 45);
 document.write('num1 value = ' + num1 + ', num2 value = ' + num2 + ', num3 value =' + num3);
}
</SCRIPT>
</head>
<body>
<form name="myform">
<input id="btnFindVal" type="button" value="Find Value" onclick="generateVal()" />
</form>
</body>
</html>