Javascript Convert Variable to Boolean

Feb 21, 2021
!!100     // true!!-1      // true!!0.1     // true!!"hello" // true!!true    // true!!0       // false!!0.0     // false!!""      // false!!false   // false!!null    // false!!undefined // false!!NaN     // false
Boolean(100)      // trueBoolean(-1)       // trueBoolean(0.1)      // trueBoolean("Hello")  // trueBoolean(true)Boolean(0)        // falseBoolean(0.0)      // falseBoolean("")       // falseBoolean(false)    // falseBoolean(null)     // falseBoolean(undefined)// falseBoolean(NaN)      // false

Doesn't work well for array and object

!!{name: 'Desmond'} // true!!['Desmond']       // true!!{}      // true!![]      // trueBoolean({name: 'Desmond'}) // trueBoolean(['Desmond'])       // trueBoolean({}) // trueBoolean([]) // true

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.