Language: EN

javascript-operadores-comparacion

Comparison Operators in JavaScript

Comparison operators allow us to compare values and obtain a boolean result (true or false) according to the relationship between the values.

These operators allow us to compare two values and determine if they are equal, different, greater, or less than, and are essential for evaluating expressions and making decisions.

The arithmetic operators of JavaScript are:

OperatorNameDescription
==EqualityCompares if two values are equal
===Strict equalityCompares if two values and their type are identical
!=InequalityCompares if two values are different
!==Strict inequalityCompares if two values and their type are not identical
>Greater thanChecks if one value is greater than another
<Less thanChecks if one value is less than another
>=Greater than or equalChecks if one value is greater than or equal
<=Less than or equalChecks if one value is less than or equal

If you want to learn more about Comparison Operators
consult the Introduction to Programming Course read more ⯈

List of comparison operators

Equality (==)

The equality operator == compares two values and returns true if they are equal, false if they are different. This operator does not take into account the data type.

5 == 5; // true
5 == '5'; // true, comparison does not take into account the type

Strict Equality (===)

The strict equality operator === compares two values and returns true if they are equal and of the same type, false if they are different.

5 === 5; // true
5 === '5'; // false, the types are different

Inequality (!=)

The inequality operator != compares two values and returns true if they are different, false if they are equal. This operator does not take into account the data type.

5 != 3; // true
5 != '5'; // false, comparison does not take into account the type

Strict Inequality (!==)

The strict inequality operator !== compares two values and returns true if they are different or of different types, false if they are equal and of the same type.

5 !== 3; // true
5 !== '5'; // true, the types are different

Greater than (>), Greater than or equal (>=)

These operators compare two numerical values and return true if the first value is greater (or greater than or equal) than the second, false if it is not.

5 > 3; // true
5 >= 5; // true

Less than (<), Less than or equal (<=)

These operators compare two numerical values and return true if the first value is less (or less than or equal) than the second, false if it is not.

5 < 10; // true
5 <= 5; // true