You mention that void is an operator, just like + is, but it seems there might be some confusion between operators and functions. void doesn't need to be "called" with parentheses, and the expression that follows it isn't an "argument".
void 0 and void(0) are the same, just as +0 and +(0) are the same.
void; is a syntax error, as is +;, whereas someFunction; isn't.
One other handy usage for the void operator is with simple arrow functions in TypeScript where undefined is the expected return type and you want to do something side-effect-ey that returns a value:
typePushFn=(n:number)=>undefinedconstarr:number[]=[]// Type error: Type 'number' is not assignable to type 'undefined'.constpushFn1:PushFn=(n)=>arr.push(n)// OKconstpushFn2:PushFn=(n)=>voidarr.push(n)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You mention that
void
is an operator, just like+
is, but it seems there might be some confusion between operators and functions.void
doesn't need to be "called" with parentheses, and the expression that follows it isn't an "argument".void 0
andvoid(0)
are the same, just as+0
and+(0)
are the same.void;
is a syntax error, as is+;
, whereassomeFunction;
isn't.One other handy usage for the
void
operator is with simple arrow functions in TypeScript whereundefined
is the expected return type and you want to do something side-effect-ey that returns a value: