Loading
Lesson 09
Courses / JavaScript for Complete Beginners
Comparison Operators in JavaScript

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: