In this lesson, we will learn to create boolean values by comparing numbers. Here's an example:
let score = 85;
let isPassed = score >= 60;
// isPassed will be true because 85 is greater than 60In this example, we compare the variable score with the number 60. The comparison score >= 60 evaluates to true if the score is 60 or higher, and false otherwise.
JavaScript provides several operators to compare numbers, and each comparison results in a boolean value:
| Operator | Description | Example | Result |
|---|---|---|---|
| > | Greater than | 10 > 5 | true |
| < | Less than | 3 < 7 | true |
| >= | Greater than or equal | 5 >= 5 | true |
| <= | Less than or equal | 4 <= 9 | true |
| === | Equal to | 8 === 8 | true |
| !== | Not equal to | 8 !== 7 | true |
Complete and run the provided code sample to see the passing score calculator in action!
Output (Console)