+ 9

What is ternary operator?

21st Mar 2021, 2:34 AM
🌍🌎🌏AIM🌏🌎🌍
🌍🌎🌏AIM🌏🌎🌍 - avatar
2 odpowiedzi
+ 8
it is basically a shortened syntax for an if else statement and has the following syntax condition ? expression1 : expression2 if the condition is truthy then expression1 is returned otherwise expression 2. Example let a = 5 let b = a > 2 ? 3 : 2 let c = a * 10 < 20 ? 4 : 6 since a > 2 is truthy, b will have the value 3 since a*10<20 is not truthy, c will have the value 6
21st Mar 2021, 2:40 AM
John Doe
+ 5
This is a shorthand for a conditional expression: condition? expression1: expression2; Or if(condition) expression1 else expression2
21st Mar 2021, 2:38 AM
Solo
Solo - avatar