---
title: "Better option from multiple statements in JavaScript"  
description: "Better option from multiple statements in JavaScript"  
author: "Anonymous User"  
published: 2021-07-19  
updated: 2021-07-19  
canonical: https://www.mindstick.com/forum/156515/better-option-from-multiple-statements-in-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Better option from multiple statements in JavaScript

I'm using [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) if statements in [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)? Is there any better way to achieve it through JavaScript?

## Replies

### Reply by Ethan Karla

It should depend on your use of the program. If you are making a program that has a lot of inappropriate conditions then you should go for the if condition. But if your condition depends on some kind of number or some string, you should replace if-else statements with switch case condition, where you have to decide if some 'case' happens, in which block of code is to be executed.

For better understanding switch to the example:

```
switch(status) {
    case 'active':
        //background green
        break;
    case 'onhold':
        //background yellow
        break;
    case 'inactive':
        //background red
        break;
    default:
        //background grey
        break;
}
```

\


---

Original Source: https://www.mindstick.com/forum/156515/better-option-from-multiple-statements-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
