5 ms·
It's a bit more than that. It can also be used to convert strings (containing numeric values) to Numbers. More commonly seen than the prefix "~~" is "|0", becau
by jhgg 12y ago
It's a bit more than that. It can also be used to convert strings (containing numeric values) to Numbers. More commonly seen than the prefix "~~" is "|0", because of it's low order precedence.
> '15'
'15'
> ~~'15'
15
> '15'|0
15
> 15.99|0
15
> ~~15 * 1.3
19.5
> 15 * 1.3 | 0
19
- owenversteeg 12y agoEveryone I know uses the + operator, I rarely see others. Funny that I'm not seeing + here.
- tracker1 12y agoWith ~~foo you will always get an integer that fits inside a 32-bit integer range... regardless of the input... invalid numbers will be 0. Whereas with a +foo you may get NaN (for an invalid decimal input). Part of this is because bitwise operations will convert whatever the input value is to a 32-bit integer value before performing the operation, and not fail (invalid input becomes 0 opposed to NaN).