DEV Community

Discussion on: 5 ways to refactor if/else statements in JS functions

Collapse
 
thexdev profile image
M. Akbar Nugroho

It's very awesome when you use guard clause to handle multiple condition instead of using if elseif else statement.

I'm a big fan of it and always use it to handle conditional statement in my code :).

Collapse
 
sylwiavargas profile image
Sylwia Vargas

Ahhhh I'm also such a fan of guard clauses! My first coding language is and was Ruby, which is obsessed with readable and pleasant code so of course, the looong code monsters that JS awakens from the deepest depth of programming hell gave me chills initially. I feel like my brain fries when I read nested if-elses... there should be an ESLint rule that obliges devs to draw a flowchart every time they write a nested if-else so it's quick and easy to follow :D