DEV Community

loading...

Discussion on: 2 Ways to Convert Values to Boolean in JavaScript

Collapse
mzaini30 profile image
Zen

I didn't use !! yet. I usually use like this:

something ? /* if true */ : /* if false */

Not this:

!!something ? /* if true */ : /* if false */
Collapse
samanthaming profile image
Samantha Ming Author • Edited

May I add something, if you don't mind 😊

something ? /* if truthy */ : /* if falsy */

Because doing something like this something will capture all truthy/falsy value and not just true/false. I've made that mistake in past, so I just want to include this friendly reminder to be mindful of πŸ‘

Collapse
mzaini30 profile image
Zen

Oh thanks πŸ˜‚

Collapse
mzaini30 profile image
Zen

I just found out that truth / falsy is different from true / false. Very cool, Javascript

Forem Open with the Forem app