What does ~~num do?
What does ~~num do?
The other way to write it is 0|num which has the advantage of only applying one bitwise op.
These tend to crop up most often in graphics oriented libraries.
Edit: Double checked the spec (it's quite readable) and the main difference is that + will coerce ignoring whitespace while parseFloat will ignore leading whitespace and parse leading digits. E.g. var x = '1.23foo'; parseFloat(x) is 1.23; +x is NaN. Neither looks like it should be faster than the other.
I tried it:
round("2.2") -> 2.2
round(2.2) -> 2.2
round("2.6") -> 2.6
round(2.6) -> 2.6
Raphaël adds 0.5 to the values in SVG in order to make one-pixel-wide lines render as a single pixel instead of two.
So ~~num I think would return the original value. The only reason I can see would be to coerce it into some kind of number type.