One, two brackets added
[] + []
The brackets do not have the function of a statement block, so the two brackets here are an array. The addition of two arrays (object types) is first converted to a value type (the base type).
1, convert to value type call valueof,[] valueof () or own
Copy Code code as follows:
var arr = [];
arr.valueof () = = = Arr; True
2, turn into a string, [] ToString is an empty string
Copy Code code as follows:
[].tostring (); // ""
String ([])//""
The result came out. Two empty strings added, the result is still an empty string. The "+" here refers to the string concatenation rather than the number addition.
add two, curly braces and brackets
Copy Code code as follows:
Note that the brace is still not an object's direct volume, but an empty statement block. So it can be removed, which is equivalent
Copy Code code as follows:
Notice that by then the seemingly two counts became the actual single op count. and the "+" operator only represents one meaning when there is only one operand: arithmetic addition. That means there's no string connection here.
The ToString () of the brackets is an empty string and is equivalent to
Copy Code code as follows:
"+" represents arithmetic addition, a string that is not numeric, and therefore converts it to a numeric type. The empty string is turned into a numeric type. In the previous article, it was 0.
So the final result is 0.
add three, brackets and braces
Copy Code code as follows:
In contrast to the above, only the parentheses and parentheses are exchanged in order. The results are not the same. After the braces are placed to the right, the curly braces discussed above are different. The braces here are an object's direct volume, not a statement block.
The operands on both sides of "+" are converted to value types: "" and "[Object Object]". Then "+" means string concatenation. That
Copy Code code as follows:
The result is "[Object]".
Four, parentheses also and they add to try
Whim! Well, although the parentheses are ambiguous, they cannot be counted as a shipment.