JavaScript `undefined` vs `void 0`

Pacerier picture Pacerier · Apr 19, 2011 · Viewed 8.3k times · Source

What exactly is the difference between undefined and void 0 ?

Which is preferred and why?

Answer

duri picture duri · Apr 19, 2011

The difference is that some browsers allow you to overwrite the value of undefined. However, void anything always returns real undefined.

undefined = 1;
console.log(!!undefined); //true
console.log(!!void 0); //false