JavaScript Comparison and Logical Operators

The JavaScript comparison and Logical operators are important topics in JavaScript. Comparison operators compare two values and give back a Boolean value: either true or false.

Comparison operators can be used in conditional statements or in loop statements to compare values and take action depending on the result.

JavaScript Comparison Operators

To determine the equality or difference between JavaScript variables or values the JavaScript comparison operators are used in logical statements.

JavaScript Comparison and Logical Operators

The table below explains the JavaScript comparison operators:

OperatorNameDescription
==Equal toReturn true if both side operands are equal
!=Not equal toReturn true if operands are not equal
===Strict equal toReturn true if operands are equal and of the same type
!==Strict not equal toReturn true if operands are equal but of different types or not equal at all
Greater thanReturn true if left side operand is greater
>=Greater than or equal toReturn true if left side operand is greater or equal to the right
Less thanReturn true if right side operand is greater
<=Less than or equal toReturn true if right side operand is greater or equal to left
JavaScript comparison operators

Which statement can be used at which time depends on the comparison value and action to be taken.

JavaScript Logical Operators

To determine the logic between variables or values the logical operators are used. Given that x = 5 and y = 2, the table below explains the logical operators:

OperatorNameDescription
&&andIt returns true if both side values are true
||orIt returns true if either of the value is true
!notIt returns true if both side values are opposite