mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat(curriculum): Add interactive examples to What Are Comparison Operators, and How Do They Work (#63246)
This commit is contained in:
+17
-1
@@ -5,12 +5,14 @@ challengeType: 19
|
||||
dashedName: what-are-comparison-operators-and-how-do-they-work
|
||||
---
|
||||
|
||||
# --description--
|
||||
# --interactive--
|
||||
|
||||
Comparison operators allow you to compare two values and return a `true` or `false` result. You can then use the result to make a decision or control the flow of your program. You use comparisons in `if` statements, loops, and many other situations where you need to make decisions based on certain conditions. Let's dive into the most common comparison operators and see how they work.
|
||||
|
||||
The greater than operator, represented by a right-angle bracket (`>`), checks if the value on the left is greater than the one on the right:
|
||||
|
||||
:::interactive_editor
|
||||
|
||||
```js
|
||||
let a = 6;
|
||||
let b = 9;
|
||||
@@ -19,8 +21,12 @@ console.log(a > b); // false
|
||||
console.log(b > a); // true
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
The greater than or equal operator, represented by a right-angle bracket and the equals sign (`>=`), checks if the value on the left is either greater than or equal to the one on the right:
|
||||
|
||||
:::interactive_editor
|
||||
|
||||
```js
|
||||
let a = 6;
|
||||
let b = 9;
|
||||
@@ -31,8 +37,12 @@ console.log(b >= a); // true
|
||||
console.log(a >= c); // true
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
The lesser than operator, represented by a left-angle bracket (`<`) works similarly to `>`, but in reverse. It checks if the value on the left is smaller than the one on the right:
|
||||
|
||||
:::interactive_editor
|
||||
|
||||
```js
|
||||
let a = 6;
|
||||
let b = 9;
|
||||
@@ -41,8 +51,12 @@ console.log(a < b); // true
|
||||
console.log(b < a); // false
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
The less than or equal operator, represented by a left-angle bracket and the equals sign (`<=`) checks if the value on the left is smaller than or equal to the one on the right:
|
||||
|
||||
:::interactive_editor
|
||||
|
||||
```js
|
||||
let a = 6;
|
||||
let b = 9;
|
||||
@@ -53,6 +67,8 @@ console.log(b <= a); // false
|
||||
console.log(a <= c); // true
|
||||
```
|
||||
|
||||
:::
|
||||
|
||||
# --questions--
|
||||
|
||||
## --text--
|
||||
|
||||
Reference in New Issue
Block a user