curriculum/challenges/english/blocks/lecture-working-with-comparison-and-boolean-operators/673271dffbc34fda31da9515.md
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
let a = 6;
let b = 9;
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
let a = 6;
let b = 9;
let c = 6;
console.log(a >= b); // false
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
let a = 6;
let b = 9;
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
let a = 6;
let b = 9;
let c = 6;
console.log(a <= b); // true
console.log(b <= a); // false
console.log(a <= c); // true
:::
What does the greater than or equals (>=) operator do in JavaScript?
It checks if the value on the left is strictly greater than the one on the right.
Think about how the greater than or equals operator combines two comparisons into one.
It checks if the value on the left is either greater than or equal to the one on the right.
It checks if the value on the right is greater than the one on the left.
Think about how the greater than or equals operator combines two comparisons into one.
It checks if both values are equal.
Think about how the greater than or equals operator combines two comparisons into one.
2
Where would you typically use comparison operators in JavaScript?
Only in arithmetic operations.
Think about when you need to check conditions in your code.
In if statements, loops, and other situations requiring decisions based on conditions.
Only when working with strings.
Think about when you need to check conditions in your code.
When defining functions.
Think about when you need to check conditions in your code.
2
Which two operators in JavaScript avoid type coercion?
== and !=.
Think about the operators that compare both value and type.
=== and !==.
> and <.
Think about the operators that compare both value and type.
<= and >=.
Think about the operators that compare both value and type.
2