void

Evaluates an expression and returns undefined.

Since ES1 Spec ↗

Syntax

void expression

Returns

undefined — Always `undefined`, regardless of the operand.

Examples

console.log(void 0);
console.log(void "anything");
Output
undefined
undefined
// Force an IIFE to be parsed as an expression
void function () {
  console.log("ran");
}();
Output
ran
const result = void (1 + 2);
console.log(result);
Output
undefined

Notes

- `void 0` is a reliable way to produce `undefined`. - Historically used in `javascript:void(0)` links to prevent navigation. - Can be used to discard the result of an async call lint-cleanly.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also