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
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 ๐
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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
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 ๐
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.