The javascript void
statement evaluates an expression, and returns the undefined
value. This is useful because the global variable undefined
can be redefined, but why does it evaluate an en expression? Most people just use 0, as in
void 0;
void(0);
Looking at Raghu's answer, the documentation says
This operator allows inserting expressions that produce side effects into places where an expression that evaluates to undefined is desired.
But can you give me an example where you can't just put void(0)
in the location where the value ùndefined` is desired, and evaluate the expression with side effects on another line?