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.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/javascript/operators/void.php