Sumit Sharma

Comparison Operators by Digital Marketing Company in Kolkata

Know then now that we understand about the triple and double equal sign let's write some simple statements comparing two numbers for example. So that should be pretty clear on how to do by now. But basically, we can say Konst my first number equals, for example, Konst my second number equals right. If you want digital marketing company in Kolkata to check if these two are equal then it would help.

That's very very simple at this point. Right. So if my first number and we know that they are both numbers we don't need to do any type of conversion. We just want to straight up you know compare these two things.

So in digital marketing company in kolkata for operators we're going to use the triple equal sign and as I said I would generally recommend to always use a triple equal sign wherever you can and to do any type conversion you know don't let javascript just explicitly you know implicitly type convert for you do it explicitly.

But basically, we can say my first number my second number if these two are equal. Let's do something to log there. We run this and give it a second year to catch up on it. oh yeah, of course, it's not going to run because these are not equal. That makes sense if we make them equal then it should run. There we go. Good stuff. So that's one way to compare numbers. What are some other comparison operators? There's a whole bunch of comparison operators in Javascript.

Again if you're coming from another programming language these are all going to be pretty familiar to you. We know already about single and are not single but double and triple equal signs. But what if we want to check if one number is greater than other numbers.

I would have set this to digital marketing company in Kolkata again. So if we want to check if say number is greater than the second number. As for whether it might be useful or this could be useful in all kinds of ways in terms of getting your mind into thinking about how this would apply in your program. What if you have some kind of I don't know banking app and you want to check what's the balance of your a bank account is the balance of your bank account greater than the amount you want to spend.

If so you should be able to run the function. If not you shouldn't. Right. So as an example of that let's say my first number is my second number is. If my first number is greater than I. So this is just very simple. Operator. Just the greater than symbol. Sometimes I forget which. Which side should be lesser.

I always think back to where the alligator so the alligator the mouth is on the left side and the smaller number it's on the right side in this case. So a clear run it again. There you see Hi there it makes sense because this first number is greater than the second number. So you know if we make this bank account balance and Konst cost of the item and it's so if the cost of the item is less than the total balance hey, congrats you can make a purchase so let's put that in here.

You can purchase this item cool so run at my first number is not fine. Oh yeah. Thanks for looking. Now you can change the bank account balance as told by digital marketing company in Kolkata. Next one cost of the item, Yeah and generally you know declaring your variables or constants or left or whatever it may be. It's a good idea to kind of make them descriptive especially considering you know a complex app you might have tons of these all over the place.

So bank balances cost item is console log you can purchase item my first number does not book. You didn't quite catch the changes. So not just take second and there you can purchase this item. Good stuff. On the other hand, if our bank account balance was less than that it's not even going to run this close.

If we had some kind of function or something embedded in here then it wouldn't run we wouldn't be able to purchase the item. It would just stop execution at this block of code. We know that by now for its statements it just stops execution here. So that's the greater than the operator. Let me put this back to We can also do greater than or equal to. Right.

If you want to be able to purchase if you have the exact amount in your bank account it makes sense that you would be able to purchase the item. So let's say you have something you want to buy and it costs exactly $. They just so happens you have that exact amount in your bank account Well that's convenient right. So if we try to run this let's see.

Doesn't execute the block of code because bank balance is not greater than the cost of the item. In fact, it's equal to the cost of the item. So how can we do that? Well, we just add an equal sign here. So this is digital marketing company in Kolkata saying if your bank account balance is greater than or equal to the cost of the item then we will execute this block of code. Right.

So if this expression evaluates to true which in this case it should run it. Hey, there we go. You can purchase this item. Good stuff. What about the cost of the item was slightly more. If we do point one let's see what happens. So we can't because it's comparing this is still a number but now it's slightly greater than the bank balance. So that's a common use case for an IF statement.

What if we wanted to do some kind of other math in here. So let's say we have bank balance cost of item Well you can forget about taxes. Right. So let's say Konst tax and initially, we'll just make it just a consistent value of cents. So you know everything in this store has cent tax no matter what it is. We can just kind of do some simple math and our if you know in our expression here.

  • Love
  • Save
    Add a blog to Bloglovin’
    Enter the full blog address (e.g.
    We're working on your request. This will take just a minute...