Ternary operator :
A ternary operator evaluates a condition and executes a block of code based on the condition.
Its syntax is:
condition ? expression1 : expression2
The ternary operator evaluates the test condition.
If the condition is true, expression1 is executed.
If the condition is false, expression2 is executed.
The ternary operator takes three operands, hence, the name ternary operator.
It is also known as a conditional operator.
Ex :
// program to check pass or fail
let marks = prompt('Enter your marks :');
// check the condition
let result = (marks >= 40) ? 'pass' : 'fail';
console.log(`You ${result} the exam.`);
Output :
Enter your marks: 78
You pass the exam.