Skip to content

Commit cc05670

Browse files
feat: add nested ternary operator
1 parent e5c4764 commit cc05670

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

part1 (Basics)/operators/06_ternary.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,23 @@ Returns one of two expressions based on a condition.
99
const age = 18;
1010
const canVote = age >= 18 ? 'Yes' : 'No';
1111
console.log(canVote); // Output: Yes
12+
13+
14+
/*
15+
? : Nested Ternary conditional operator
16+
Nested ternary means using a ternary inside another ternary.
17+
Useful when you have multiple conditions to check.
18+
*/
19+
20+
const userAge = 20;
21+
22+
const status = userAge < 13
23+
? "Child"
24+
: userAge < 18
25+
? "Teenager"
26+
: userAge < 60
27+
? "Adult"
28+
: "Senior";
29+
30+
console.log(status); // Output: Adult
31+

0 commit comments

Comments
 (0)