Why is the JavaScript "do-nothing" snippet void(0)
often written as such? Why not just void 0
? Is there any particular reason why the 0
is so often enclosed in (unnecessary) parenthesis?
MDN says that void(0)
is equivalent to void 0
, as void
is an operator.
Could this possibly be the same type of confusion as enclosing the typeof
operand in parenthesis? (Like typeof(value) === 'string'
?) Is it the same case where many people seem to believe void
is a function?
This answer states that
void(0)
is just the smallest script possible that evaluates asundefined
.
But void 0
is actually one character shorter, and seems to behave equivalently, at least in Chrome 43.