var ie =!-[1,];
This code was previously known as the world's shortest ie decision code before IE9. The code is short but contains a lot of JavaScript basics in it. In This example , the code executes with the array's toString () method called First , and execution [1,].tostring () will get "1" in ie6,7,8. The expression then becomes !-"1,". then try to convert "1," to a numeric type to get Nan, and then a negative value for Nan is still nan. Final Execution! Nan returns True. The following is a review of the JavaScript knowledge involved in the code by decomposing this statement:
The browser's array literal resolution difference
[1,] means that an array is defined using the literal number of JavaScript. In ie6,7,8, the array has two elements, and the values in the array are 1,undefined respectively. In a standard browser, the undefined after the first element is ignored, and the array contains only one element 1.
The ToString () method of an array
Calling the ToString () method of an Array object invokes the ToString () method for each element in the group, if the value of the element is null or undefined, the empty string is returned, and the resulting value of each item is spelled into a string separated by a comma ",".
Unary minus operator
When using the unary minus operator, if the operand is a numeric type, then the value is directly negative, otherwise it will attempt to convert the operand to a numeric type, and the conversion process is equivalent to executing the number function and then negative to the resulting result.
logical non-operation
Returns true if the operand is Nan, null, or undefined when performing a logical negation.
The above knowledge can be derived from the code var ie =!-[1,] In fact, equivalent to the var ie =! (-number ([1,].tostring ())); true in Ie6\7\8. If there is anything wrong with the analysis or have any different opinions welcome corrections!