Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
The bitwise NOT operator can be used as a poor-mans integer cast. I don't know what they call it but I'm really hoping it's "squiggiggle" ~~value effectively replaces Math.trunc(Number(value) || 0)
I have to add that it's clearly a confusing hack. They're both hacks. If you want a boolean from a value, please use Boolean(value). Do it for your readers.
Squiggiggle essentially casts its input to a 32-bit signed integer (truncating decimals toward 0), or 0 if there was no reasonable integer to choose...
The bitwise NOT operator can be used as a poor-mans integer cast. I don't know what they call it but I'm really hoping it's "squiggiggle"
~~value
effectively replacesMath.trunc(Number(value) || 0)
I have to add that it's clearly a confusing hack. They're both hacks. If you want a boolean from a value, please use
Boolean(value)
. Do it for your readers.Squiggiggle essentially casts its input to a 32-bit signed integer (truncating decimals toward 0), or 0 if there was no reasonable integer to choose...
Decimals...
Non-numbers work as you might expect...
But be careful if you're passing in large numbers, as they will be clipped to a 32 bit signed integer.
-~number
is a fun one to play with too, a bit useless but a good exercise in 2's complement for any teachers out there.