JS ⟩ statement ⟩ expression ⟩ operator ⟩ unary ⟩ void
(operator)
evaluates its operand, then discards the value and returns undefined.
// ⭐ syntax: void <expr> const count = () => void counter++; // ⭐ void: discard return value
void (replit)
let counter = 0; // ⭐ void: discard return value const count = () => void counter++; const count2 = () => { counter++ }; // same as above count(), // undefined counter, // 1 count2(), // undefined counter++, // 2
JS 冷知識:你所不知道的 void
JavaScript: The Definitive Guide ⟩ 4.13.6 The void Operator
void operator void expr or void(expr) evaluates the given expr and then returns undefined.
void
expr
void(
)
undefined
some transpilers turn undefined into void 0.
Last updated 2 years ago