Looking in the jQuery core I found the following code convention:
nth: function(elem, i, match){
return match[3] - 0 === i;
},
And I was really curious about the snippet match[3] - 0
Hunting around for ‘-0’ on google isn’t too productive, and a search for ‘minus zero’ brings back a reference to a Bob Dylan song.
So, can anyone tell me. Is this some sort of performance trick, or is there a reason for doing this rather than a parseInt or parseFloat?
Based on a few quick and dirty benchmark runs,"1234" - 0was about 50% faster thanparseInt("1234")and 10% faster than+"1234"in Firefox 3.6.Update:
My “quick and dirty” benchmark was not very useful because it was just converting the string “1234” in a loop. I tried again using a random list of numbers, and the results are all over the map. The three methods are all within 400-500 ms on this computer except when they jump to 1300 ms! I think garbage collection is interfering. Here is some code to play with in Firebug, in case I did something stupid: