← Back to context

Comment by draw_down

3 years ago

> void 0 (a fancy obfuscated way of saying undefined)

Kind of. But it was possible at one point, maybe still is, to rebind `undefined` to some other value, causing trouble. `void` is an operator, a language keyword; it’s guaranteed to give you the true undefined value. (In other words, the value whose type is `undefined`.)

If you’re coding against an environment as adversarial as these people clearly believe they are, you’d go with `void` as well.

Another reason to use `void 0` is that "void 0" takes only 6 characters while "undefined" takes 9, saving some bandwidth. It is common practice for JavaScript minifiers to use this substitution.

  • Given it will be gzip-compressed in transport, does this really save a meaningful amount of bandwidth?

    • It’s really more that there is no reason not to do it. Void is marginally safer as well as shorter, so any minifier/transpile step etc will make this substitution.