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…

--

--

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