May 25, 2023
Program to use Ternary Operator JavaScript Language
let a = 10;
let b = 20;
let max;
max = a > b ? a : b;
console.log("Max Number is =", max);
Output
Max Number is = 20
Steps Description
- Declare three variables
a, b
andmax
- Initialize three variables with value of 10, 20 respectively
a=10, b=20
andmax
- Ternary operator works like if else
- condition is checked first value is true expression1 displayed condition is false expression2 displayed
console.log
inbuild function to display max variable number
by : Suhel Akhtar
Quick Summary:
Ternary Operators using in JavaScript program