This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.



The void operator evaluates an expression and then returns undefined.


void expression


In this example, void(0) is used to return undefined to the link’s href property, so that the browser will not attempt to load a URL and the function in the onclick event can be executed instead.

<!DOCTYPE html>
<title>JavaScript void example</title>
<a href="javascript:void(0)" onclick="myFunction()">Click here to execute the function.</a>


The expression argument is any valid JavaScript expression.

The void operator evaluates its expression and returns undefined. It is useful in situations where an expression should be evaluated but you do not want a result returned to the rest of the script.

Void works only on unary expressions, thus: void x, y; will set only the x variable to undefined.


void(0) is equivalent to void 0 and returns the undefined value.


  • Microsoft Developer Network: Article