Converting truthy/falsy values to boolean

Logical operators are a core part of JavaScript, here you can see a a way you always get a true or false no matter what was given to it.

You can convert a truthy or falsy value to true boolean with the !! operator.

!!"" // false
!!0 // false
!!null // false
!!undefined // false
!!NaN // false

!!"hello" // true
!!1 // true
!!{} // true
!![] // true

Leave a Reply

Your email address will not be published.