DEV Community

loading...

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

Collapse
jonrandy profile image
Jon Randy

It isn't a shorthand, it is part of how the language works. An 'if' statement expects a boolean, so it will coerce whatever you give it to a boolean - no need to do the conversion yourself

Collapse
samanthaming profile image
Samantha Ming Author

Exactly Jon! I remember being told auto coercion is this scary beast. But then if you understand it, you can make the beast work for you 😊. It's just another thing JavaScript tries to help. And if you know what it's trying to do, why not let it 😉

Collapse
wrldwzrd89 profile image
Eric Ahnell

Yes, after thinking about it, I realized that you’re coercing to Boolean and negating, then undoing negation. My “shorthand” remark was meant in the sense of fewer characters to type.

Forem Open with the Forem app