-
Book Overview & Buying
-
Table Of Contents
Object-Oriented JavaScript - Second Edition - Second Edition
By :
Operators take one or two values (or variables), perform an operation, and return a value. Let's check out a simple example of using an operator, just to clarify the terminology:
> 1 + 2;
3
In this code:
+ is the operator
The operation is addition
The input values are 1 and 2 (the input values are also called operands)
The result value is 3
The whole thing is called an expression
Instead of using the values 1 and 2 directly in the expression, you can use variables. You can also use a variable to store the result of the operation, as the following example demonstrates:
> var a = 1; > var b = 2; > a + 1; 2 > b + 2; 4 > a + b; 3 > var c = a + b; > c; 3
The following table lists the basic arithmetic operators:
|
Operator symbol |
Operation |
Example |
|---|---|---|
|
|
Addition |
> 1 + 2;
3
|
|
|
Subtraction |
> 99.99 – 11;
88.99
|
|
|
Multiplication |
> 2 * 3;
6
|
|
|
Division |
> 6 / 4;
1.5
|
|
|
Modulo, the remainder of a division |
> 6 % 3;
0
>... |
Change the font size
Change margin width
Change background colour