w3resource

JavaScript: void operator

Description

The void operator is used to evaluate a JavaScript expression without returning a value.

Syntax

void (expression)
void expression

Example -1:

The following web document shows how the void operator is used.

HTML Code

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<title>JavaScript void operator example</title>
</head>
<body>
<a href="javascript:void(alert('Thank you.'))">Click here to see a message</a>
</body>
</html>

View the example in the browser

Example -2:

In the following web document, void operator is used to call a function.

HTML Code

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<title>JavaScript void operator (calling function) example</title>
</head>
<body>
<script type="text/javascript">
</script>
<a href="javascript:void(testfunc())">
Click here to call testfunc()</a>
</body>
</html>

View JavaScript void operator ( call a function) example in the browser

See also

Conditional Operator
comma
delete
function
in
instanceof
new
this
typeof

Previous: JavaScript: typeof operator
Next: JavaScript: Block statement

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.