JavaScript Quick Tips Quick Tips

Ditch !! and try Boolean() instead

< 1 min read

Using !!someVariable might seem smart to turn a value into a boolean in JavaScript, but is it intuitive for someone who doesn’t know this JavaScript "trick" to understand?

Try using Boolean(someVariable) to make your intentions easier for everyone to understand. Write JavaScript for humans 🙌


I’ve created a test script which confirms that Boolean() and !! behave the same way:

Original tweet