May 25, 2023

Ternary Operator in JavaScript Language

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);


Max Number is = 20

Steps Description

  1. Declare three variables a, b and max
  2. Initialize three variables with value of 10, 20 respectively a=10, b=20 and max
  3. Ternary operator works like if else
  4. condition is checked first value is true expression1 displayed condition is false expression2 displayed
  5. console.log inbuild function to display max variable number

by : Suhel Akhtar

Quick Summary:

Ternary Operators using in JavaScript program