meaning of void (0) in JavaScript
Overview
The void operator executes the statement passed to it, and then returns undefined.
Grammar
void expression
The void operator is usually used only to get The original value of the undefined, usually with void (0) (equivalent to void 0 ).
Why don't we just use undefined ?
Undefined is not a reserved word ( A global variable in some environments of JavaScript). This means that undefined is an available variable name and you can assign it any value. For example:
// alerts "undefined" var undefined = "New value"//Alerts "New Value "
Let's look at an example used in a link:
Javascript:uri executes the code in the URI and replaces the current page content with the returned value, unless the return value is undefined.
< a href = "javascript:void (0);" > //TAP no action </ a > < a href = "javascript:void (document.body.style.backgroundcolor= ' green ');" > //Click the background to turn green </ a >
Therefore, you cannot safely use undefined, and the value it returns is not necessarily what you expected. void is not overwritten and is always returned to undefined.
Why is void 0, why is 0 others not?
Other values are also available, such as 1,"Hello World". The use of 0 is because it is relatively short and concise and conforms to the language habit.
Reference:
MDN void Opter
Https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void
StackOverflow 's Answer
What does ' void 0 ' mean?
Http://stackoverflow.com/questions/7452341/what-does-void-0-mean
Meaning of void (0) in JavaScript