Conditional (ternary) operator
condition ? if true : else
. If the condition is met, the code after the question mark (?
) is executed. If it is not met, the code after the semicolon (:
) is executed. In simple if-else scenarios the conditional (ternary) operator can save a lot of code.In this example we use the conditional (ternary) operator to assign a value to the variable text depending on the value of num. Adjust the code such that the value of text will be 'num is greater than 3'
.
Get a premium membership to access this content: