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...

## re: JavaScript: Double Not Operator? VIEW POST

FULL DISCUSSIONThe 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,

pleaseuse`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.