Should I use "void 0" or "undefined" in JavaScript

Should I use void 0or undefinedin JavaScript to unassign a value, for example:

event.returnValue = void 0;
// or
event.returnValue = undefined;
+4
source share
3 answers

If you are using a modern browser (which supports javascript 1.8.5), using undefinedand void 0most likely the same ( as it undefinedbecomes unavailable for writing ), except that it voidcan take an expression as a parameter and evaluate it.

In older browsers (which do not support javascript 1.8.5). Better to use void 0. Take a look at this example:

console.log(undefined);
var undefined = 1;
console.log(undefined);

He will print

1

undefined . ( ). , undefined , as void - , javascript undefined. , fooobar.com/questions/804256/....

:

, , void 0.

+20

"void 0" . "undefined" - , . :

undefined = 3;

event.returnValue, undefined. "void" - , . "void 0" undefined.

+3

void undefined, "void (0)" ( "void 0" ). undefined ( , , ).

fooobar.com/questions/3196/...

undefined, .

+1
source

All Articles