DEV Community

Discussion on: What is the Double bang (!!) operator in JavaScript?

Collapse
 
wparad profile image
Warren Parad

I feel like they article made this whole concept really complicated. It's actually simple, What is !!?. It's the same as Coerce to boolean. It would do the same as a method Convert.toBoolean(value) where value is truthy or falsy and the result is true or false.

You need this because some parameters are expected to be true or false and not truthy and falsy. Boolean(value) doesn't actually coerce a value to a boolean, it's unfortunately less useful than that. And so using !! (the double NOT) is a great way to coerce a value to a boolean.