What is the difference between undefinedand void 0?
undefined
void 0
Which is preferable and why?
The difference is that some browsers allow you to overwrite a value undefined. However, it void(anything)always returns real undefined.
void(anything)
undefined = 1; console.log(!!undefined); //true console.log(!!void(0)); //false
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 . - . .
null
true
JS , , void 0 void(0) .
void(0)
undefined , , undefined.
Additional information in the link: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/void
Use undefined. Its more famous than void(0).