|
|
|
|
|
by some-1
5029 days ago
|
|
-0+'12' (and 0+'12') doesn't convert it to a number, it converts the zero to a string and then concatenate them to the string "012". And Firefox optimize it: Function('return -0+"12"').toString();
Returns: "function anonymous() { return "012";}"
So there is no conversion going on in the test, it just returns the string "012". No wonder that it is fast. See my comment above for another jsperf where it is converted in each test. |
|
However, my point still stands: Why are some operators (and in particular unary minus, which is probably the most commonly used one) so much slower than others?