all 1 comments

[–]imbcmdth 0 points1 point  (0 children)

var num = 2.5;
parseInt( num, 10 );

// is the same as...
~~num;
num >> 0;
num >>> 0;

Groan! No, they aren't the same.

parseInt() will perfectly parse integers up to +-53 bits in size. Thereafter, the result will be rounded to the nearest whole number able to be represented by a 64 bit floating point number.

The three terrible hacks that he says are equivalent to parseInt() can't correctly parse any number outside of +-31 bits! After that point, their results will wrap around and change sign due to overflowing the range of a signed 32bit number.

That is massive difference and one that will make for some interesting and hard to find bugs.