1. Add brackets
[] + []
Brackets have no block clause, so the two brackets here are an array. To add two arrays (object types), convert them to value types (basic types ).
1. to convert the value type, call valueOf, [] valueOf () or your own.
Copy codeThe Code is as follows:
Var arr = [];
Arr. valueOf () === arr; // true
2. convert it to a string. The toString of [] is a null string.
Copy codeThe Code is as follows:
[]. ToString ();//""
String ([]) // ""
The result is displayed. The two empty strings are added, and the result is still a null string. That is, "+" indicates the string connection, not the addition of digits.
2. Add braces and brackets
Copy codeThe Code is as follows:
{} + []
Note that the braces here are still not the object's direct quantity, but empty statement blocks. Therefore, you can remove it, which is equivalent
Copy codeThe Code is as follows:
+ []
Note: In this case, the number of two operations is changed to the actual number of single operations. The "+" operator only represents one operation number: arithmetic addition. That is, there is no meaning of string connection.
The toString () in the brackets is an empty string, which is equivalent
Copy codeThe Code is as follows:
+ ""
"+" Indicates arithmetic addition. A string is not a number, so it is converted to a number. Convert a null string to a numeric type as mentioned in the previous article, which is 0.
The final result is 0.
3. Add brackets and braces
Copy codeThe Code is as follows:
[] + {}
Compared with the above, the brackets and parentheses Exchange Order. Results are different. After placing the braces on the right, they have different meanings from the braces discussed above. The braces here are a direct volume of objects rather than statement blocks.
The operation numbers on both sides of "+" are converted to value types: "" and "[object Object]". "+" Indicates a string connection. That is
Copy codeThe Code is as follows:
"" + "[Object Object]"
The result is "[object Object]".
4. Try adding parentheses with them.
Whimsy! Okay, although parentheses have many meanings, they cannot be used as the number of operations.