JavaScript `undefined` vs` void 0`

What is the difference between undefinedand void 0?

Which is preferable and why?

+27
source share
4 answers

The difference is that some browsers allow you to overwrite a value undefined. However, it void(anything)always returns real undefined.

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

undefined It has the normal semantics of variables, which even strict mode cannot correct and requires a search at runtime. It can be obscured like any other variable, and the global variable is undefinednot read-only in ES3 by default.

void 0 - undefined . , null true . - . .

+16

JS , , void 0 void(0) .

undefined , , undefined.

Additional information in the link: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/void

+1
source

Use undefined. Its more famous than void(0).

0
source

All Articles