| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Operators/void | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.
void undefined .
const output = void 1;
console.log(output);
// Expected output: undefined
void console.log("expression evaluated");
// Expected output: "expression evaluated"
void (function iife() {
console.log("iife is executed");
})();
// Expected output: "iife is executed"
void function test() {
console.log("test function executed");
};
try {
test();
} catch (e) {
console.log("test function is not defined");
// Expected output: "test function is not defined"
}
void expression;
void undefined .
undefined void 0 void(0) . undefined .
void 2 == "2"; // undefined == '2', false
void (2 == "2"); // void true, undefined
(IIFE) void function .
void (function iife() {
var bar = function () {};
var baz = function () {};
var foo = function () {
bar();
baz();
};
var biz = function () {};
foo();
biz();
})();
javascript: URI , URI undefined . void undefined . .
<a href="javascript:void(0);"> </a>
<a href="javascript:void(document.body.style.backgroundColor='green');">
</a>
: javascript: .
Arrow functions introduce a short-hand braceless syntax that returns an expression. This can cause unintended side effects by returning the result of a function call that previously returned nothing. To be safe, when the return value of a function is not intended to be used, it can be passed to the void operator to ensure that (for example) changing APIs do not cause arrow functions' behaviors to change.
button.onclick = () => void doSomething();
This ensures the return value of doSomething changing from undefined to true will not change the behavior of this code.
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-void-operator |
This page was last modified on 2025 2 11 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |