DEV Community

Cover image for Boolean coercion
icncsx
icncsx

Posted on

Boolean coercion

Use !! to see how JavaScript would coerce a real value into a boolean-ish interpretation.

console.log(!!" ") // true
console.log(!!"")  //  false
console.log(!!"0") //  true
console.log(!!0) //  false
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
maverick2502 profile image
Nurullo

Heya, actually the last expression console.log(!!"0") should be true not false :)

Collapse
 
icncsx profile image
icncsx

You're absolutely right. I meant to say !!0 :)