javascript-void keyword written in front
ECMA-262 defines the keyword (keyword) supported by ECMAScript, and the keyword cannot be used as an identifier for the ECMAScript program (indetifiers). The ECMA-262 standard defines the following keywords:
Break Do instanceof typeof Case Else New varCatch finally return voidContinue for Switch whileDebugger function This withdefault if Throw Deleteinch Try
void
According to the ECMA-262 definition, void is one of 26 keywords in JavaScript, so what is void in JavaScript and what is different from void in other languages? As defined by the ECMA official standard, Void is a unary operator and returns undefined, regardless of what is behind the expression.
The following are described in the ECMA-262 specification:
Void can be any expression (unaryexpression), with a return value of only undefined:
Note: Do not write in this form void 1 + 1, because the void ratio + priority is higher, then it becomes (void 1) + 1
Basic usage 1, void 0
function joke () { var undefined = "Hello world"; // will output "Hello World" }varfunction (key) { returnfunction (obj) { returnnullvoid 0 : Obj[key]; };};
2, javascript:void (0)
You can use Javascript:void (0) to block links from the default jump behavior, and here is an example of an MDN document:
do nothing</a><a href= "javascript:void (Alert (' Hello word! '))" >click me!</a>
Note: Regardless of how many usages of void (unaryexpression) Extend, its essence is to perform unaryexpression and return undefined.
Questions
back to the official standard definition of void ECAM-262, since the return value of void is always undefined, then why do you need to call Getvale (expr). In fact, Void is designed to implement the expression behind the execution and ignore the expression results returned undefined, if the result of an expression is a reference, and does not take value, and the value of this process may have side effects (side-effect), So take one more getvalue step.
Reference ECMAScript 5.1MDN
javascript-void keyword