Ternary operator multiple conditions JavaScript | Example code

Ternary operator more than one condition is possible with nesting it. Let’s see example for that in this tutorial.

Example of Ternary operator multiple conditions JavaScript

HTML example code for

If mark -> 1 then result = A

If mark -> 2 then result = B

else result = C

Output:

HTML Ternary operator multiple conditions JavaScript

JS Ternary functions with multiple conditions

Same code with function to easy use. This version to be fairly readable

Output: 1

Another Example for better understanding

Multiple conditions ternary operator JavaScript function.

Output:

Multiple conditions ternary operator JavaScript function

Do comment if you have any doubts and suggestion on this question based topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.