This operator allows the insertion of expressions that produce side effects in places where an expression that evaluates the action {{jsxref ("Global_Objects / undefined")}} is desired.
The void operator is often used only to get the undefined primitive value, usually using "void (0)" (which is equivalent to "void 0"). In these cases, the global variable {{jsxref ("Global_Objects / undefined")}} can be used instead (assuming it has not been assigned a non-default value).
Immediate call of function expressions
When we use an immediate call of the function expressions, null values can be used to force the function keyword to be treated as an expression rather than a statement.
void function iife() {
var bar = function () {};
var baz = function () {};
var foo = function () {
bar();
baz();
};
var biz = function () {};
foo();
biz();
}();
JavaScript URIs
When a browser follows a javascript: URI, it evaluates the code in the URI and then replaces the contents of the page with the returned value, unless the returned value is {{jsxref ("Global_Objects / undefined", "undefined")}} . The void operator can be used to return {{jsxref ("Global_Objects / undefined", "undefined")}}. For example:
<a href="javascript:void(0);">
Clique aqui para não fazer nada
</a>
<a href="javascript:void(document.body.style.backgroundColor='green');">
Clique aqui para o papel de parede ser verde
</a>