Double exclamation mark in Javascript

Written by Lyoneel on in programming
 1 min

Double exclamation mark in Javascript

It’s an operator that returns a boolean, ‘falsy’ is false, ’truthy’ is true

It’s an operator that returns a boolean, ‘falsy’ is FALSE, ’truthy’ is TRUE.

Let’s see a few examples:

!!0             // false
!!null          // false
!!undefined     // false
!!''            // false

!!'something'   // true
!!"text"        // true
!!12345         // true
!!0.2           // true
!![]            // true
!![0, 2, 5]     // true
!!{}            // true
!!{age: 1}      // true

I stumbled across this a few days ago. I hope you find it useful