Writing cleaner code by avoiding switch case and nested if in Javascript:

There are ways in which you can reduce number of lines of code and make the code looks cleaner.

One way is to avoid switch statements and nested loop

for example lets see the below functions:

simple switch statements:



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
Praveen David Mathew

Praveen David Mathew


An ISTQB certified Software Test Engineer and an enthusiastic fast learner with a passion for technology. linkedin : https://www.linkedin.com/in/praveendvd