
The ternary operator is a shorthand way to write a conditional statement in JavaScript. It is also known as the ternary conditional operator.
Ternary Operator JavaScript
Here is the syntax for the ternary operator:
condition ? expression1 : expression2
The condition is evaluated first. If it is true, expression1 is executed. If the condition is false, expression2 is executed.
The video below will show you how to use the ternary operator in JavaScript.
Code Ternary Operator JavaScript
Here is an example of using the ternary operator javascript snippet:
<script>
let x = 30;
let y = 50;
let max = (x > y) ? x : y;
console.log(max)
</script>