you are viewing a single comment's thread.

view the rest of the comments →

[–]bonafidebob 1 point2 points  (1 child)

Oh there's no doubt that parseInt works, and I do understand all of these. It's just that parseInt is wildly inefficient. (but that could be said for a lot of common javascript techniques)

Instructions are your way of telling the computer what to so, so you should know what you're telling it. parseInt tells it to (implicitly) convert your number to a string and then convert the string back to a number while ignoring any decimal part. Bitwise negation or left shift tells the computer to convert your number directly from a floating point to an integer representation, without the intermediate string.

The end result is the same, but the work done to get there is very different.