Lesson 12: Arithmetic Operators and Assignment Operators
7 Principal Arithmetic OPERATORS:
Arithmetic operators are used to do figure mathematical operations between variables and/or values. We are covering the most common ones here and the rest will be covered in the advanced tutorial. The seven main arithmetic operators are:
- + Addition: adds
- - Subtraction: subtracts
- * Multiplication: multiplies
- / Division: divides
- ++ Increment: increases by one
- -- Decrement: decreases by one
- % Modulus: divides and returns the remainder
6 Principal Assignment OPERATORS:
Assignment operators are used to assign values to JavaScript variables. There are some other assignment operators, however we are only going to deal with the main ones that you will be using. You will learn the rest in the advanced tutorial. The 6 main assignment operators are:
= Makes the preceding variable equal to the following value or variable.
+= Makes the preceding variable equal to itself plus the following value or variable.
Example: x+=y is the same as x=x+y
-= Makes the preceding variable equal to itself minus the following value or variable.
Example: x-=y is the same as x=x-y
*= Makes the preceding variable equal to itself multiplied by the following value or variable.
Example: x*=y is the same as x=x*y
/= Makes the preceding variable equal to itself divided by the following value or variable.
Example: x/=y is the same as x=x/y
%= Makes the preceding variable equal to the modulus of itself and the following value or variable.
Example: x%=y is the same as x=x%y
As you can see by the above examples, with the exception of the plain equals sign, these are JavaScript’s answer to short hand. Notice how they allow the code to be shortened a bit.
*Note: This lesson and the next are the only two that do not have accompanying code snippets because these two are mainly for reference. That’s why I made them the last two lessons, because they are where an appendix would normally go. I did not want to change the flow of the tutorial though, so I made them lessons as well.
In the next lesson, we cover all of the reserved words in JavaScript so that you may have them for reference. You may want to reference the next lesson whenever you are not sure if a word is a reserved word or not as you can not use reserved words for variable or function names. Also you will surely be wanting to reference this lesson as well whenever you forget what operator to use.
Now go on to Lesson 14, Reserved Words: Yes, we skipped Lesson 13 out of silly superstition….
Javascript Discussion
- - Google Chrome / Mozilla?
- - Delete text after focus c
- - Statistics
- - Tabs using javascript
- - Select all values in te
Javascript Source Code
- - E-mail Validation
- - Required Fields
- - Alert User Depending On Browser
- - All Details About Browser
- - More Browser Detection





