Hacker News new | ask | show | jobs
by mynegation 2294 days ago
“!!” is a way to convert any “falsy” value to a Boolean false. E.g. if you have a flag “enableFoo” that can take the values of undefined, null, numerical zero, NaN, empty string, and actual Boolean false, all these values will be converted to false with “not not”. All other values, including - ironically - “false” as a string, will be converted to Boolean true.
1 comments

I even once got a `!!!someVariable` in a codebase I inherited. It's what convinced me that the previous devs weren't doing weird things to work around a bad backend: they just didn't know what they were doing