May 25, 2023
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
andb
- Initialize both variables with value of 10 and 10 respectively
a=10, b=10
- Equal
==
comparison operator checks the condition that botha
andb
have the same value - The values of
a
andb
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
- Declare two variables
c
andd
- Initialize both variables with value of 10 and 10 respectively
c=10, d=10
- Equality
===
comparison operator checks the condition that bothc
andd
have the same value and data type - The values of
c
andd
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
- Declare two variables
e
andf
- Initialize both variables with value of 10 and '5' respectively
e=10, f='5'
- Not equal
!=
comparison operator checks for the condition that bothe
andf
values are not equal - The values of
e
andf
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
- Declare two variables
g
andh
- 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 ofg
andh
are not the same - The values of
g
andh
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
- Declare two variables
i
andj
- Initialize both variables with value of 10 and 5 respectively
i=10, j=5
- Greater than
>
comparison operator checks whether the value ofi
is greater than that ofj
- The values of
i
andj
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
- Declare two variables
k
andl
- Initialize both variables with value of 10 and 5 respectively
k=10, l=5
- Less-than
<
comparison operator checks whether the value ofk
is less thanl
- The values of
k
andl
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
- Declare two variables
m
andn
- 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 ofm
is greater than and equal ton
- The values of
m
andn
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
- Declare two variables
s
andt
- 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 ofs
is less than and equal tot
- The values of
s
andt
variables are displayed with the help of console.log inbuilt function
by : Suhel Akhtar
Quick Summary:
Comparison Operators using ( ==, ===, !=, !==, >, <, >=, <= ) in JavaScript program with example