Skip to content
Advertisement

How to split nested ternary operator into normal if else condition

I was trying to understand ternary operator into normal if else condition.

JavaScript

how to understand this multiple nested condition

Advertisement

Answer

It’s equivalent to the following:

JavaScript

The conditional operator approach could be refactored to be more readable by putting the NOTHING condition first, though, if you wanted:

JavaScript
Advertisement