i

JavaScript

Comparison operators

Comparison operators:

Operators like =, < or > are used to compare if variables/values are equal. They return true, if equal, false otherwise.

The below table explains the operators, its usage along with an example.

Operator

Description

Example

Return value

==

Equals – checks only for value

var a = 7;

a == 8

false

===

strict equals – checks for equal value and equal type

var a = 7;

a === 7;

true

!=

not equal – checks for value

var a = 7;

a != 8

true

!==

strict not equals – checks for both value and type

var a = 7;

a !== 7;

true

>

greater than

var a = 7;

a > 5

true

> =

greater than or equal to

var a = 7;

a >=7;

true

<

lesser than

var a = 7;

a < 5

false

 

<=

lesser than or equal to

var a = 7;

a <= 7;

true