If you're seeing this message, it means we're having trouble loading external resources on our website.
If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.
Introduction
The field of computer science has many foundations in mathematical logic. If you have a familiarity with logic, you know that it involves truth tables, Boolean algebra, and comparisons to determine equality or difference.
The JavaScript programming language uses operators to evaluate statements that can aid in control flow within programming.
In this tutorial, we’ll go over logical operators. These are commonly used with conditional
statements, and the if
, else
, and else if
keywords, as well as the ternary operator. If you are interested in learning more about conditional statements first, refer to How To Write Conditional Statements in JavaScript.
Comparison Operators
In JavaScript, there are a number of comparison operators that you can use to evaluate whether given values are different or equal, as well as if a value is greater than or less than another. Often, these operators are used with stored values in variables.
Comparison operators all return a
Boolean [logical] value of true
or false
.
The table below summarizes the comparison operators available in JavaScript.
==
| Equal to |
!=
| Not equal to |
===
| Strictly equal to with no type conversion |
! ==
| Strictly unequal to with no type conversion |
>
| Greater than |
>=
| Greater than or equal to |
80;
f > '30';
We’ll receive the following output:
In the first
instance, Greater than or equalSimilarly, the operator for greater than or equal to will evaluate whether one operand meets the threshold of the other. This operator is typed as Our examples:
Because Less thanThe less than operator appears as the mirror version of the
greater than operator: Chủ Đề |