JavaScript

May 25, 2023

Comparison Operators in JavaScript Language

Program to use Equal ( == ) Comparison Operators JavaScript Language


let a = 10;
let b = 10;
console.log(a == b);

Output


true

Steps Description

  1. Declare two variables a and b
  2. Initialize both variables with value of 10 and 10 respectively a=10, b=10
  3. Equal == comparison operator checks the condition that both a and b have the same value
  4. The values of a and b variables are displayed with the help of console.log inbuilt function

Program to use strict equality ( === ) Comparison Operators JavaScript Language


let c = 10;
let d = 10;
console.log(c === d);

Output


true

Steps Description

  1. Declare two variables c and d
  2. Initialize both variables with value of 10 and 10 respectively c=10, d=10
  3. Equality === comparison operator checks the condition that both c and d have the same value and data type
  4. The values of c and d variables are displayed with the help of console.log inbuilt function

Program to use not equal ( != ) Comparison Operators JavaScript Language


let e = 10;
let f = '5';
console.log(e != f);

Output


true

Steps Description

  1. Declare two variables e and f
  2. Initialize both variables with value of 10 and '5' respectively e=10, f='5'
  3. Not equal != comparison operator checks for the condition that both e and f values are not equal
  4. The values of e and f variables are displayed with the help of console.log inbuilt function

Program to use Strict inequality ( !== ) Comparison Operators JavaScript Language


let g = '5';
let h = 5;
console.log(g !== h);

Output


true

Steps Description

  1. Declare two variables g and h
  2. Initialize both variables with value of '5' and 5 respectively g='5', h=5
  3. strict inequality !== comparison operator conditions that both the value and the data type of g and h are not the same
  4. The values of g and h variables are displayed with the help of console.log inbuilt function

Program to use Greater than ( > ) Comparison Operators JavaScript Language


let i = 10;
let j = 5;
console.log(i > j);

Output


true

Steps Description

  1. Declare two variables i and j
  2. Initialize both variables with value of 10 and 5 respectively i=10, j=5
  3. Greater than > comparison operator checks whether the value of i is greater than that of j
  4. The values of i and j variables are displayed with the help of console.log inbuilt function

Program to use Less than ( < ) Comparison Operators JavaScript Language


let k = 10;
let l = 5;
console.log(k < l);

Output


false

Steps Description

  1. Declare two variables k and l
  2. Initialize both variables with value of 10 and 5 respectively k=10, l=5
  3. Less-than < comparison operator checks whether the value of k is less than l
  4. The values of k and l variables are displayed with the help of console.log inbuilt function

Program to use Greater than or equal to ( >= ) Comparison Operators JavaScript Language


let m = 10;
let n = 10;
console.log(m >= n);
console.log(5 >= 10);

Output


true
false

Steps Description

  1. Declare two variables m and n
  2. Initialize both variables with value of 10 and 10 respectively m=10, n=10
  3. Greater than-or-equal >= comparison operator checks the condition that the value of m is greater than and equal to n
  4. The values of m and n variables are displayed with the help of console.log inbuilt function

Program to use Less than or equal to ( <= ) Comparison Operators JavaScript Language


let s = 10;
let t = 5;
console.log(s <= t);

Output


false

Steps Description

  1. Declare two variables s and t
  2. Initialize both variables with value of 10 and 5 respectively s=10, t=5
  3. Less than or equal to <= comparison operators check the condition that the value of s is less than and equal to t
  4. The values of s and t variables are displayed with the help of console.log inbuilt function

by : Suhel Akhtar

Quick Summary:

Comparison Operators using ( ==, ===, !=, !==, >, <, >=, <= ) in JavaScript program with example