The void Operator
Description
The void operator evaluates an expression and returns undefined.
Example
<a href="javascript:void(0);">
Useless link
</a>
<a href="javascript:void(document.body.style.backgroundColor='red');">
Click me to change the background color of body to red
</a>
Try it Yourself »
About void
The void operator is often used to obtain the primitive value undefined.
Using "void(0)" is useful when evaluating an expression without using the return value.
javascript:void(0) is an expression commonly found in HTML, particularly within <a> tags. It serves to prevent the default action of a link, which is to navigate to a new page or reload the current one.
The void operator evaluates any expression and always returns the primitive value undefined.
In the context of javascript:void(0), 0 is simply an argument passed to the void operator, which is discarded, effectively doing nothing.
Browser Support
void() is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |