This operator allows the insertion of expressions that produce side effects in places where an expression that evaluates the action {{jsxref("Global_objects/Undefined", "undefined")}} is desired.
The void operator is often used only to obtain the undefined primitive value, usually using "void(0)" (which equates to "void 0"). In these cases, the global variable {{jsxref("Global_objects/Undefined", "undefined")}} can be used instead (assuming it has not been assigned to a non-standard value).
Immediate call of function expressions
When we use an Instant Call of function expressions, null values can be used to force the keyword of the function to be treated as an expression instead of a declaration.
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>
When the contents are copied from somewhere, it is interesting to inform the source in this case, the MDN (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void). Additionally, your reply contains untranslated content.
– OnoSendai
Sorry I’m new here
– Daniel Correa Santos