5 Tips to Write Better Conditionals in JavaScript

Jecelyn Yeen
Sep 17, 2018 · 1 min read

When working with JavaScript, we deal a lot with conditionals, I have 5 tips to share with you for writing better / cleaner conditionals.

  1. Use Array.includes for Multiple Criteria
  2. Less Nesting, Return Early
  3. Use Default Function Parameters and Destructuring
  4. Favor Map / Object Literal than Switch Statement
  5. Use Array.every & Array.some for All / Partial Criteria

As usual. please read the full article👇in scotch.io, code samples provided (free of course, with better syntax highlight).

Jecelyn Yeen

Written by

Coder. Diver. Speak English, Mandarin, Javascript, C# and more.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade