js if else ternary code example
Example 1: js ternary
condition ? ifTrue : ifFalse
Example 2: javascript ternary
// example:
age >= 18 ? `wine` : `water`;
// syntax:
// <expression> ? <value-if-true> : <value-if-false>
Example 3: using ternary operator in javascript
// 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.`);