Example 1 — void IIFE
Run a function and ignore its return.
JavaScript
void function () { console.log("run"); }(); How It Works
- Function runs for side effects.
void expression evaluates the expression and returns undefined. The classic idiom void 0 is a reliable undefined value.
console.log(void 0);
console.log(void (1 + 2)); Run a function and ignore its return.
void function () { console.log("run"); }(); void 0 cannot be overwritten.
console.log(void 0 === undefined); Avoid navigating to a returned value.
console.log("void keeps result undefined"); CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful