void
In JavaScript, the void keyword is a unary operator that evaluates the expression after it and then returns undefined, whatever value the expression produced. The expression still runs, so any side effects such as function calls or assignments still happen.
The result is always the undefined primitive. Like typeof and delete, void binds tighter than binary operators, so void 2 === "2" compares undefined with "2". Parentheses around the operand, as in void (2 === "2"), apply void to the whole comparison. The form void 0 is a short way to write undefined that older code and minifiers still produce.
JavaScript void Keyword Syntax
The void operator takes a single expression:
void <expression>
JavaScript void Keyword Examples
The void operator returns undefined for any operand, applies only to the operand right after it, and can discard an arrow function’s return value:
> void 0
undefined
> void 2 === "2"
false
> const cart = [];
undefined
> const addItem = (item) => void cart.push(item);
undefined
> addItem("apple")
undefined
> cart
[ 'apple' ]
The arrow function still calls .push(), but void discards the new length that .push() returns, so addItem() returns undefined.
JavaScript void Keyword Use Cases
- Keeping a concise arrow function from leaking its body’s return value
- Running an IIFE written as
void function () { ... }(); - Marking a promise as intentionally not awaited
- Writing
javascript:void(0)links that do nothing in browsers
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 4, 2026