Comparison Operators in JavaScript Language
Ascending Order, Descending Order
On this page
Equal ( == ) Comparison Operators
Program to use Equal ( == ) Comparison Operators JavaScript Language
let a = 10;
let b = 10;
console.log(a == b);
Output
true
Steps Description
- Declare two variables a and b
- Initialize both variables with value of 10 and 10 respectively a=10, b=10
- Equal == comparison operator checks the condition that both a and b have the same value
- The values of a and b variables are displayed with the help of console.log inbuilt function
strict equality ( === ) Comparison Operators
Program to use strict equality ( === ) Comparison Operators JavaScript Language
let c = 10;
let d = 10;
console.log(c === d);
Output
true
Steps Description
- Declare two variables c and d
- Initialize both variables with value of 10 and 10 respectively c=10, d=10
- Equality === comparison operator checks the condition that both c and d have the same value and data type
- The values of c and d variables are displayed with the help of console.log inbuilt function
not equal ( != ) Comparison Operators
Program to use not equal ( != ) Comparison Operators JavaScript Language
let e = 10;
let f = '5';
console.log(e != f);
Output
true
Steps Description
- Declare two variables e and f
- Initialize both variables with value of 10 and ‘5’ respectively e=10, f=’5′
- Not equal != comparison operator checks for the condition that both e and f values are not equal
- The values of e and f variables are displayed with the help of console.log inbuilt function
Strict inequality ( !== ) Comparison Operators
Program to use Strict inequality ( !== ) Comparison Operators JavaScript Language
let g = '5';
let h = 5;
console.log(g !== h);
Output
true
Steps Description
- Declare two variables g and h
- Initialize both variables with value of ‘5’ and 5 respectively g=’5′, h=5
- strict inequality !== comparison operator conditions that both the value and the data type of g and h are not the same
- The values of g and h variables are displayed with the help of console.log inbuilt function
Greater than ( > ) Comparison Operators
Program to use Greater than ( > ) Comparison Operators JavaScript Language
let i = 10;
let j = 5;
console.log(i > j);
Output
true
Steps Description
- Declare two variables i and j
- Initialize both variables with value of 10 and 5 respectively i=10, j=5
- Greater than > comparison operator checks whether the value of i is greater than that of j
- The values of i and j variables are displayed with the help of console.log inbuilt function
Less than ( < ) Comparison Operators
Program to use Less than ( < ) Comparison Operators JavaScript Language
let k = 10;
let l = 5;
console.log(k < l);
Output
false
Steps Description
- Declare two variables k and l
- Initialize both variables with value of 10 and 5 respectively k=10, l=5
- Less-than < comparison operator checks whether the value of k is less than l
- The values of k and l variables are displayed with the help of console.log inbuilt function
Greater than or equal to ( >= ) Comparison Operators
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
- Declare two variables m and n
- Initialize both variables with value of 10 and 10 respectively m=10, n=10
- Greater than-or-equal >= comparison operator checks the condition that the value of m is greater than and equal to n
- The values of m and n variables are displayed with the help of console.log inbuilt function
Less than or equal to ( <= ) Comparison Operators
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
- Declare two variables s and t
- Initialize both variables with value of 10 and 5 respectively s=10, t=5
- Less than or equal to <= comparison operators check the condition that the value of s is less than and equal to t
- The values of s and t variables are displayed with the help of console.log inbuilt function