Transcript from the "Comparison & Equality Operators" Lesson
>> Some of these other operators, they are similar to math class. They tell us how things compare. So we also have operators for like greater than, less than, greater than, or equal to, less than or equal to, and they involve our friends the angle brackets. So, the right angle bracket is greater than the left angle bracket is less than and then if we put an equal sign after those are the or equal to versions, and we can kind of guess what type of value?
>> A boolean, true or false, right? True or false, 5 is greater than 4? We can confirm that. Good, we can confirm that.
[00:02:43] So, what am I talking about the strict versus the loosey goosey version, I am gonna ask you all to poke around and figure out. For each of these examples, does the strict triple equals operator, do the same thing as the loosey goosey double equals operator? And if they are different, how are they different?
[00:03:39] All right, so these operators, these equal equal equal or equal equal strict loosey-goosey, what do they do? Do they do things? Let's find out. Okay. So, what did we find this first row? Number 1, triple equal number 1 versus number 1, double equal number 1. Do they do the same thing or different things?
>> Same thing. And in both cases we get the answer true. Nice. How about the second line? Sring 1 equals string 1?. Same or different?
>> Same and the answer, true. Cool. All right. We're just checking our bases here, making sure we're not losing it.
[00:04:25] What about the last line? So number one, triple equals number one. Let's try it out. Sorry, string 1, number 1, triple equals string 1, false. Is that what you expect? I'm seeing nods, because we said these are two different things, right? One is a number one is a string.
[00:04:49] They're not the same. They have something in common I guess maybe, but they're totally different things, one is like talking about a number and the other is the actual number. What about the loosey-goosey double equals? So number one loosey-goosey equals letter or string one. This returns true, was anyone surprised by this?
>> Triple equals, probably tries to determine what type of data format it is versus double equals just interprets the value itself.
>> Interesting, okay, so this has something to do definitely with the type of values that we're dealing with, right? And the triple equal is, seems to care about the type of value.
[00:06:28] It's saying, all right, these two things they look kinda different but let me try to pretend that they are the same value. What it's doing is what's called casting or converting the values to be the same type so that it can compare them more closely. And it's saying, okay, if we convert these to the same value, the same type of value, then they would be the same thing.
[00:07:43] So that triple equal and the exclamation equal equal instead of the loosey goosey, two equals versions because almost always, the type of your data matters. So I bring up these loosey goosey versions just to tell you that they're out there and to tell you be careful that you're not using the loosey goosey when you think you're using the strict one.
[00:08:37] Anybody have any other guesses about other operators that are out there? We saw one earlier the percentage and the double asterisks for modulo and or remainder and exponentiation.
>> Interesting. A coalesce function. Can you tell us a little bit about coalesce?
>> In SQL, it evaluates multiple values to determine if any of them have a something that's assigned to it. Once it finds one, that's a sign that has something assigned to it, it says, okay, I'll take the very first one.
>> Right, okay.
>> So useful sometimes with SQL.
[00:09:32] Well, there's not really the answer to the question, is not really something equivalent to coalesce in SQL, but there is something that's called a nullish coalescing operator. What is that? I don't know. Let's find out. Let's play around. So we have a bunch of like logical operators that like this one is one of them.
[00:10:15] You can look it up in the operators page, as we saw before. Cool. So once again, the takeaway from this whole course is MDN, [LAUGH] just kidding.
>> Someone was saying AND and OR plus, plus.
>> AND and OR, plus, plus, yes. Okay, so these are also operators that we can.
[00:10:41] If we go to I don't actually know if this will work if we yes, okay, we can even type it into the search box. So AND AND is another logical operator for logical AND. Again, we'll come back to it when we talk about conditionals, and truth values and things like that and the other one was plus plus.
[00:11:16] And that we can always look up the details of and like how does it work again and what's an example and all of that good stuff is in our friend MDN. So anytime you're curious about a particular operator that you see in somebody else's code maybe, or you know the name of the thing you wanna do, but you can't remember what the symbol is MDN is your friend, MDN is your friend.
[00:11:37] Yeah, I'm gonna be saying that a lot.