w3resource logo


JavaScript Operators

JavaScript : void operator

Secondary Nav

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



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program