Lesson 09
Comparison Operators in JavaScript
Summary
# JavaScript Comparison Operations
Welcome back to NBK Attack World! In this video, we will explore comparison operations in JavaScript.
## Key Points Covered:
1. **Basic Comparison Operators**:
- Greater than (`>`)
- Less than (`<`)
- Greater than or equal to (`>=`)
- Less than or equal to (`<=`)
2. **Boolean Values**:
- The result of comparison operations will yield a boolean value (`true` or `false`).
3. **Examples**:
- `7 > 4` returns `true`
- `4 > 7` returns `false`
- `5 <= 5` returns `true`
- `100 >= 33` returns `true`
- `101 >= 100` returns `false`
- `100 >= 100` returns `true`
4. **Styling**:
- It's a good practice to include spaces before and after operators for clarity, although it's not mandatory.
5. **Equality and Inequality**:
- To compare equality, use double equal signs (`==`).
- Example: `2 == 2` returns `true` while `2 == 3` returns `false`.
- For inequality, use an exclamation mark followed by an equal sign (`!=`).
- Example: `2 != 3` returns `true`, while `4 != 4` returns `false`.
## Conclusion
We reviewed how to use comparison operators in JavaScript, enabling you to compare values and obtain boolean results effectively. Practice using these operators in your browser console to deepen your understanding.
Thank you for watching, and keep practicing until next time!
Video Transcript
Welcome back to NBK Attack World
on our journey to learn JavaScript
So guys, this video will be about
comparison operations in JavaScript
We're going to do some mathematical comparisons
We already learned some math that JavaScript can do some basic math
addition, subtraction, multiplication, division
We're going to talk about comparison, we're going to compare things
Remember the greater than, less than, greater than or equals to
equals to that kind of stuff, so we're going to do it right now
So let's start with
greater than. To do a greater than for example
number 7 is obviously greater than 4
So we can do the greater than
the result of this operation if we press enter right now, it's a
value that's either true or false
Remember that value is called a boolean
So this comparison
7 is greater than 4
That's going to be true
Now if I put 4 greater than 7
it's obviously false, right?
So that's comparison, JavaScript
in your browser console
Now we know 4 is less than 7, so we can do less than
and if you want it to be less
than or equal to, you can do like so
You put the less than sign followed by the equal sign together
and if I put 5 less than
or equal to 5 is going to be true
By convention I always put a space before and after the
operator just to make things clean, but you don't have to have it
You can do like this, it's fine, but I strongly advise
you to have this style
Now let's learn greater than or equal to
100 is greater than or equal to what? 33? True
But if I put 101 it's going to be false
If I put 100 it's going to be true
So there you have it
Let's review, so we learn greater than
less than, greater than or equal to, less than or equal to
Right? I assume you already have a mathematical background
So that's why I go a little bit quick on these
So I just wanted to know that these comparison operators are available to you
in JavaScript and you're going to be using them a lot
So don't forget them
You can just open up your console and practice using these operators
to see what you get, true or false
Now let's go on and learn about equal or not equal
So let me clear this
Where's the Chrome? Is a clear console right here? This icon
Now the two, verify that for example two is equal to two
You would have to use, well mathematics
is a single equal sign, right?
Actually in programming typically the single equal sign will mean
assignment operation when you like the finding variables
That's why we have to do a double equal sign
for comparison, okay? So be careful with that
When you're doing the equal to two, it's two equal
to two, you have to use the double equals
Okay? And this is going to be true
But two is not equal to three, is it? False
Now if you want to say, okay, I want this guy
not equal to, where you going to use the
exclamation point, okay?
So unfortunately we cannot type the, we can type
the character with the equals with the bar
on top, crossing it, but that's not very convenient to type it
on a keyboard, so the way they do not equal to is with
the exclamation with equal sign, okay?
So that's not equal to
In this case two not equal to
three, that's going to be watched, true or false?
True, okay?
Now it's four not equal to
four, that's obviously false
Okay, looking good
So let's review, double equal to equal to
exclamation point and equal to not equal to
AKA different
Alright?
So that's it for comparison operators in JavaScript
You'll learn how to compare greater than, less than
greater than or equal to, less than or equal to
and not equal to
Hope you liked this video and keep on practicing your browser console, try different numbers
and different comparison operators to see what you get
the boolean values, right, true or false? Thank you so much for watching
and until the next time, bye!
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: