Arithmetic Operators

7 minutes
Share the link to this page
Copied
  Completed
Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value. The standard arithmetic operators are addition (+), subtraction (-), multiplication (*), and division (/).

Transcript

Hello, in this JavaScript video, I am going to cover arithmetic operators. They might be or already be able to guess that the arithmetic operators are something to do with mathematics. And if you did, you're right. But let's create some, I think we need to create variables. So if I do a console dot log, my console, log out, go back refresh. And arithmetic operator is something like this.

If I say four plus eight, this is addition. operator. We get a value of 12. See where I'm going with this. I'm just going to write out the call operator though and correction. I will act in the exact same order everything duplication, Asterix is the multiplication symbol in programming.

And finally division and the division symbol. If I go back refresh, we get lucky. Go back to add, we get 12 take away, you should get minus four times four times at three to four divided by eight is five. Okay, that's pretty cool stuff. And you know, you could do as many as you want, you could do that. If you want to do all you could do add an extra task, you know, feel free to combine them, but it's just as you would write mathematics in real life.

Okay, so that is, you know, really, really awesome. Now, let me show you three other operators. So the next one is called the modulus, node, no. Copy and Paste. Save time. And less likely for me to make a mistake even though we're just modulus operator and the modulus operator The format is to define the modulus operator three.

I mean is, is the sensible thing. So so do five module a three, three low value of two for a moment just think or pause the video and see if you can figure out what's happened and thought about it okay, so for what has happened is basically got the remainder it checks hi times free golden fly for your free six okay Congo you know, above the by you So goes into it once and the remainder is, you know, three or five my three plus seven in here he goes three, six. If you go doctor you go nine so that's too big to free six. The remainder is once I do reload There you go. We have a remainder of what? You might be thinking what would happen if I were to replace this division or deform modular site as an extra task, I want you to have a go back.

Okay, so let's have a look at a another type of operators still arithmetic and if the increment and decrement I'm actually going to create a variable for this for num equals 10. And I'm going to console log deserves the console dot log console log num. And also want to mention everywhere that um, you know number, you could use a variable instead. That's fine. You could you know, assign this to a variable, that is fine. You could well you could you know, pretty much put this anywhere I was putting the console log just because easy to demonstrate.

Okay, so We got this login. So let's have a look see what we get. Get me cool. What happens if I were to do something really crazy? And I'm going to do it I'm going to do something really crazy if I duplicate this and I thought the num plus plus seven co line my thinking Whoa What is happening here? Let me show you.

If I refresh, we get 11. So this is the equivalent of a comment equivalent saying num equals itself. Yes. I think it is there a you know a minor version. And yeah, there is literally just this minus due to this is the increment operator and all literally just create another variable for number two kalidas tan and we want them to know two ways that an increment decrement operator. And it's the same thing as saying no two equals it's minus one.

And if a printed out last two values to be 10, nine, and they are not forgot to change this from minus there are two minuses. There we go. We have two minuses. And that's it. That's the increment or decrement. That'll sound right increment and decrement operators.

You can put this directly if you want into here. That is coin ago, and let's have a look. see what we get. We get 10 more thinking, what is going on we caught up in here we can. The reason that didn't work is I want to show you something Going to create one more sex. And this applies for the increment and decrement.

So I'll only do it for one. I'll do for the decrement one, three before I can do it here instead. Again, what value are we going to get? We get 1010 emotion can Didn't we decrement it to value what do we get? We get nine. And what happens is, if I were to do this, put the minus minus or the plus plus before the variable.

It says nine on that line as well. So depending on its position, if it's before it does, the know takes away one from that variable first. Then the rest of the line. If afterwards, it does the rest of the Then performs that decrement or increment hence why this will printing out 10 because it hadn't actually performed the decrement operation when you know it had that value. So that's it for arithmetic operators. There are many more operators in coding and JavaScript.

I've got separate videos covering them. Feel free to take a look at the GitHub page for more information. And as usual, I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.