Yes you can go wild nesting ternaries. I find this version to be fairly readable:

var foo = (
  bar === 'a' ? 1 : // if 
  bar === 'b' ? 2 : // else if 
  bar === 'c' ? 3 : // else if
  null // else 
);

but that's not a widely shared opinion, and you should probably stick to if/else or switch when working on a team.

Answer from Damon on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Conditional_operator
Conditional (ternary) operator - JavaScript | MDN
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark (?), then an expression to execute if the condition is truthy followed by a colon (:), and finally the expression to execute if the condition is falsy.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-use-multiple-ternary-operators-in-a-single-statement-in-javascript
How to use multiple ternary operators in a single statement in JavaScript ? - GeeksforGeeks
September 19, 2024 - In the syntax, if condition1 is incorrect then Expression3 will be executed else if condition1 is correct then the output depends on condition2. If condition 2 is correct, then the output is Expression1.
🌐
Codecademy
codecademy.com › forum_questions › 50a735d192bf860b2000077c
Ternary operator more than one condition | Codecademy
I understand the ternary operator for the conditional statement is as shown below: var Name = "Mike"; if (Name === "Mike" { ...
🌐
freeCodeCamp
freecodecamp.org › news › the-ternary-operator-in-javascript
JavaScript Ternary Operator – Syntax and Example Use Case
January 6, 2023 - The ternary operator is a conditional operator which evaluates either of two expressions – a true expression and a false expression – based on a conditional expression that you provide.
🌐
SitePoint
sitepoint.com › blog › javascript › quick tip: how to use the ternary operator in javascript
Quick Tip: How to Use the Ternary Operator in JavaScript — SitePoint
November 6, 2024 - The ternary operator can be used for value assignment, executing expressions based on a condition, and checking if a variable is null or undefined. It can also handle multiple conditions, similar to if…else if…else statements, by nesting or chaining conditions within the operator’s expressions.
🌐
YouTube
youtube.com › watch
JavaScript Basic 111: Use Multiple Conditional (Ternary) Operators | FreeCodeCamp - YouTube
🎬 **"Ternary Tango: Multiple Moves, One Groovy Dance!"** 🔗Lesson Link: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-j...
Published   September 5, 2023
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-ternary-operator
JavaScript Ternary Operator | GeeksforGeeks
The ternary operator can be nested, allowing you to perform multiple conditional checks in a single line of code.
Published   April 15, 2025
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript ternary operator
JavaScript Ternary Operator
November 15, 2024 - Let’s take some examples of using the ternary operator. The following example uses the ternary operator to perform multiple operations, where each operation is separated by a comma.
🌐
Programiz
programiz.com › javascript › ternary-operator
JavaScript Ternary Operator (with Examples)
Suppose the use enters 35. Then the condition marks >= 40 evaluates to false. So the second expression fail is assigned to the result variable. In JavaScript, a ternary operator can be used to replace certain types of if..else statements.
🌐
Medium
medium.com › @pradipkaity › mastering-ternary-operators-in-javascript-how-to-use-multiple-in-a-single-statement-65e5c6c01c7f
Mastering Ternary Operators in JavaScript: How to Use Multiple ...
May 27, 2025 - One of the most concise and elegant ... conditions in a single line of code. But did you know that you can use multiple ternary operators in a single statement?...
🌐
DEV Community
dev.to › wizdomtek › mastering-the-javascript-ternary-operator-a-comprehensive-guide-5388
Mastering the JavaScript Ternary Operator: A Comprehensive Guide - DEV Community
October 27, 2024 - Maintain Readability: If the ternary operator makes the code less readable, opt for an if...else statement. The condition is simple and straightforward. You want to assign a value based on a condition. It enhances code conciseness without sacrificing readability. Dealing with complex conditions or multiple nested conditions. The expressions involve side effects or multiple statements. Readability is compromised. The JavaScript ...
🌐
Flexiple
flexiple.com › javascript › javascript-ternary
JavaScript Ternary Operator – Syntax and Example Use Case - Flexiple
It's particularly useful for ... ternary operators in JavaScript, one ternary operation is placed inside another, allowing for multiple conditions to be evaluated in a concise manner....
🌐
Stack Abuse
stackabuse.com › guide-to-the-ternary-operator-in-javascript
Guide to the Ternary Operator in JavaScript
May 30, 2022 - Let's rewrite this if-else block using ternary operator : let age = 21; let result = age >= 20 ? "User can view content" : "User cannot view content"; console.log(result); Basically, anything before the question mark (?) is the condition we are checking. The other two operands are expressions, the first one before the semi-colon (:) and the second after.
🌐
Refine
refine.dev › home › blog › tutorials › how to use the javascript ternary operator
How to Use the JavaScript Ternary Operator | Refine
October 8, 2024 - Though it’s not always the most readable, you can chain ternary operators to handle multiple conditions. It works like an inline if/else if/else block. Here’s an example: const grade = score > 90 ?