Code 85
Published in

Code 85

Replace Equality Expressions with indexOf() in JavaScript

Simplify your conditions and improve readability

Photo by Chase Clark on Unsplash

Let’s put ourselves in a fictitious scenario where a message prints only during the hours of 8AM, 10AM, and 2PM. The code block might look something like this…

const d = new Date();
const hour = d.getHours() + 1;
if(hour === 8 || hour…




Plain language programming tutorials for non-developers

Recommended from Medium

Design Systems for React Developers |

Interactive apps in Flutter

ViewModel + LiveData + Retrofit2 + RecyclerVeiw Create an APP

// from Twitter

Expat family relive Italian earthquake horror

All you need to know about waits in selenium.

What is facade design pattern?

Getting Started with Angular 4

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jonathan Hsu

Jonathan Hsu

Top writer with 2.5M+ views.

More from Medium

How to Speed Up Your JavaScript Code (+10 Guidelines)

Multidimensional Arrays In JavaScript: The Right Way

A 3-dimensional glass cube.

Why […‘👩‍❤️‍💋‍👨’] returns [‘👩’, ‘‍’, ‘❤’, ‘️’, ‘‍’, ‘💋’, ‘‍’, ‘👨’] in JavaScript?

7 Differences Between Arrow Functions and Traditional Functions