DEV Community

loading...

Discussion on: Top 20 JavaScript tips and tricks to increase your Speed and Efficiency

Collapse
lexlohr profile image
Alex Lohr

About the logical operators in 5, you should always be aware of their defined behavior:

  • a && b yields b if a is truthy, otherwise false
  • a || b yields the first value of a, b that is truthy

This means that a || b && c will return a if it a is truthy. If you are using a tool like prettier, you can just use brackets everywhere and let it figure out where they can be removed safely.

Collapse
techygeeky profile image
Kapil Raghuwanshi🖥 Author • Edited

I second that @lexlohr ! Nice suggestion to keep in mind.