CKTIS / JavaScript
The void operator
The unary `void` operator evaluates its operand, discards its value, and produces `undefined`. It preserves side effects and does not catch exceptions. The expression `void 0` provides the value `undefined`.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
void expression
void (expression)void is a unary JavaScript operator and a reserved word: it cannot be used as a variable name. It evaluates its operand and retrieves its value, then discards that value. If evaluation completes normally, the entire expression produces undefined, not null, false, or the string "undefined".
The syntax is void expression. Parentheses in void (expression) group the operand; they do not indicate a function call. The expression void 0 produces undefined without referring to the identifier undefined. The operator binds more tightly than ===: void 0 === undefined means (void 0) === undefined.
Discarding the value does not skip operand execution. Function calls, state changes, and getters still run. Exceptions propagate: void does not catch them or make reading an undeclared variable safe.
In the example, next() increments calls and returns 42. The operator discards 42, so result holds undefined. The expected output lines are 1 and true.
Examples
let calls = 0;
function next() {
calls += 1;
return 42;
}
const result = void next();
console.log(calls);
console.log(result === void 0);Result
1 true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.