DEV Community

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

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.