What Is JavaScript Void Keyword
What Is JavaScript Void Keyword
JavaScript
Void Keyword?
or:
void(func())
javascript:void(func())
//-->
</script>
</head>
Example 1:
The most common use for this operator is in a client-side javascript: URL,
where it allows you to evaluate an expression for its side effects without
the browser displaying the value of the evaluated expression.
Here the expression alert('Warning!!!') is evaluated but it is not loaded
back into the current document:
<head>
<script type="text/javascript">
<!--
//-->
</script>
</head>
<body>
<a href="javascript:void(alert('Warning!!!'))">Click
me!</a>
</body>
Example 2:
Another example the following link does nothing because the expression
"0" has no effect in JavaScript. Here the expression "0" is evaluated but it
is not loaded back into the current document:
<head>
Example 3:
Another use for void is to purposely generate the undefined value as
follows:
<head>
<script type="text/javascript">
<!--
function getValue(){
var a,b,c;
a = void ( b = 5, c = 7 );
document.write('a = ' + a + ' b = ' + b +' c = ' + c
);
}
//-->
</script>
</head>