Which logical operator is used to determine if a value is greater than another value?

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.

OperatorWhat it means
== 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:

Output

false true

In the first instance, 72 is less than 80, so the first expression evaluates to false. In the second instance, 72 is in fact greater than '30', and the operator does not care that the number is a string, so the expression evaluates to true.

Greater than or equal

Similarly, the operator for greater than or equal to will evaluate whether one operand meets the threshold of the other. This operator is typed as >= a kind of compound between greater than [>] and the equal sign [=].

Our examples:

let g = 102;

g >= 90;

g >= 103;

Output

true false

Because 102 is a larger number than 90, it is considered to be greater than or equal to 90. Because 102 is less than 103, it is false to state that 102 >= 103. If either 90 or 103 were a string data type, the expressions would also evaluate the same.

Less than

The less than operator appears as the mirror version of the greater than operator:

Chủ Đề