How to find largest of three numbers in JavaScript

Largest Numbers

On this page

Largest Numbers

Find largest of three numbers in JavaScript program

let a = 10;
    let b = 20;
    let c = 5;
    if (a > b && a > c) {
        console.log("a is Big ", a);
    }
    
    if (b > a && b > c) {
        console.log("b is Big ", b);
    }
    
    if (c > a && c > b) {
        console.log("c is Big ", c);
    }
    

Output

b is Big  20
    

Steps Description

  • Declare three variables a, b and c
  • Initialize three variables with value of 10, 20 and 5 respectively a=5, b=10 and c=5
  • if statement a greater b && operator a greater c check the condition a is big
  • if statement b greater a && operator b greater c check the condition b is big
  • if statement c greater a && operator c greater b check the condition c is big
  • console.log inbuild function to display big variable number