DEV Community

Discussion on: 8 JavaScript Tips & Tricks That No One Teaches 🚀

Collapse
 
strativd profile image
Strat Barrett

I'm a big fan of !! which gets the boolean value of (pretty much) anything:

let truthiness = !!12       //=> true
let truthiness = !!0        //=> false
let truthiness = !!'string' //=> true
let truthiness = !!''       //=> false
// BUT LOOK OUT FOR OBJECTS... 👀
let truthiness = !![]       //=> true
let truthiness = !!{}       //=> true
Enter fullscreen mode Exit fullscreen mode

! is the opposite so !! becomes the boolean value !! 😄

Collapse
 
parkio profile image
Chris

The Boolean() constructor is another great way to interpret falsey values.

Collapse
 
garvitmotwani profile image
Garvit Motwani

Thanks for sharing! 🙏🙏

Some comments have been hidden by the post's author - find out more