Var ie =! -[1,];
This code was called the world's shortest IE judgment code before IE9. The code is short but contains a lot of basic javascript knowledge. In this example, the toString () method of the array is called before code execution. When [1,]. toString () is executed, "1," is returned in IE6, 7, and 8 ,". Then the expression is changed! -"1 ,". Then try to convert "1," to the numerical type to get NaN, and then take the negative value of NaN to get the value still NaN. Last executed! NaN returns true. Next, we will use this statement to review the javascript knowledge involved in the Code:
Differences in array literal parsing of browsers
[1,] indicates that an array is defined literally using an array of javascript. In IE6, 7, and 8, the array has two elements: 1 and undefined. The undefined after the first element is ignored in the standard browser, and the array contains only one element 1.
Array toString () method
When you call the toString () method of an array object, the toString () method is called for each element in the array. If the element value is NULL or undefined, an empty string is returned, then, the values of each item are combined into a string separated by commas.
Unary minus sign Operator
When the unary minus sign operator is used, if the operation Number is of the numerical type, the Operation Number is directly negative. Otherwise, the Operation Number is first converted to the numerical type. The conversion process is equivalent to executing the Number function, then, the negative result is obtained.
Logical non-operation
True is returned if the operand is NaN, NULL, or undefined when the logical non-operation is performed.
Through the above knowledge, we can get the code var ie =! -[1,]; in fact, it is equivalent to var ie =! (-Number ([1,]. toString (); the value in IE678 is true. If there is anything wrong with the analysis, or if you have any different opinions, please correct them!