www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons JavaScript Arithmetic Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
Lesson 45
Lesson 46
Lesson 47
Lesson 48
Lesson 49
In the previous two lessons we learned about the JavaScript variables. In this lesson we will explore the operators that are available in JavaScript to do maths with the variables.

Arithmetic in JavaScript is fairly simple we can add, subtract, divide and multiply our variables. In addition we also have a special modulus(%) operator that returns the division remainder. We can also store the results of our arithmetic in variables.

The following example declares and defines two variables, applies different JavaScript operators on them and and stores the result in a third variable:

a = 4;

b = 10;

c = a + b; // addition: c now contains the value 14

d = b - a; // subtraction: d now contains the value 6

e = a * b; // multiplication: e now contains the value 40

// the * operator is used for multiplication in JavaScript

f = b / a; // disision: f now contains the value 2.5

g = b % a; // modulus (division remainder): g now contains the value 2

e = a++; // increment operator: increments the operand by 1
// e now contains the value 5. We can also write the above as ++a

f = a--; // decrement operator; a now contains the value 3
// can also be written as --a

Next >>> Lesson No. 7: JavaScript If...Else





Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.