DEV Community

Cover image for Hidden power of || and &&

Hidden power of || and &&

Nick K on May 24, 2021

TLDR: Logical operators actually return one of the operands, so you can refactor code using this feature. Usually, you may see || and &&amp...
Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

Elvis cuts out not only undefined, but also null.

Still, it is much safer than short circuiting.

Collapse
 
hexnickk profile image
Nick K

Thanks! I've added a note to the post and mentioned you πŸ™

Collapse
 
peterlunch profile image
Peter

Nice post, short circuit logic has the added benefit of also making your code a lot cleaner.