When one no isn't enough
Today’s treat, a cheat sheet. You know the no (!) expression, you use it all the time to check for falsy values. But what about the no-no (!!)? This is the one that turns value into a Boolean value.
Last week, I had to look it up for a specific case and thought to myself, “This won’t be the last time I need this.” So here it is, served on a silver plate, the !! cheat sheet.
| Value | !!value |
|---|---|
| true | true |
| false | false |
| 1 | true |
| 0 | false |
| -1 | true |
| "" | false |
| "good vibes" | true |
| null | false |
| undefined | false |
| NaN | false |
| {} | true |
| [] | true |
This is really useful when you want a clean true or false, and not just something truthy or falsy.