void

JSstatementexpressionoperatorunary ⟩ void

(operator)

evaluates its operand, then discards the value and returns undefined.

// ⭐ syntax: void <expr>
const count = () => void counter++;    // ⭐ void: discard return value
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

Last updated