### Welcome to the Javascript Arithmetic Homepage, Guest!

Javascript | A typical thing to do with numbers

### Arithmetic

Javascript has built in arithmetic operators that will perform arithmetic on numbers; literals or variables. A normal arithmetic operation operates on two numbers. The two numbers can be literals or variables, I might add.

• - Subtraction
• * Multiplication
• / Division
• % Modulus
• ++ Increment
• -- Decrement

var x = 10 + 5;
Here we are declaring a variable, x, and performing addition on two numbers

var a = 10;
var b = 5;

var c = a + b;
Here we are declaring three variables, two have set numbers, and one is performing arithmetic on two variables

### Operators and Operands

The numbers in an arithmetic formulation are called opperands. The operation is defined by an operator. So,

[Operand] 15 [Operator] + [Operand] 5

• - The subtraction operator will subtract two numbers
• * The multiplication operator will multiply two numbers together
• / The division operator will divide two numbers together
• % The modulus operator will the remainder of the division
• ++ This will increment the number by one
• -- This will decrement the number by one

### Operator Procedence

Javascript has a built in operator precendence; the precendence describes the order in which operators will be performed in an arithmetic expression. The precedence is just the way a computer will read the arithmetic statement. x = 5 + 2 * 4; is a totally different statement than x = 5 + (2 * 4). The first expression will yield 28, while the second expression will yield 13. Precedence is very similar to what it was in school. Multiplication and division have higher priority than addition and subtraction, while anything in parentheses will be computed first. Anything with the same precedence will be executed from left to right.

Operator Description Example
( ) Expression grouping (3 + 4)

. Member person.name
[] Member person["name"]

() Function call myFunction()
new Create new Date()

++ Postfix Increment i++
-- Postfix Decrement i--

++ Prefix Increment ++i
-- Prefix Decrement --i
! Logical not !(x==y)
typeof Type typeof x

* Multiplication 10 * 5
/ Division 10 / 5
% Modulo division 10 % 5
** Exponentiation 10 ** 2

- Subtraction 10 - 5

<< Shift left x << 2
>> Shift right x >> 2
>>> Shift right (unsigned) x >>> 2

< Less than x < y
<= Less than or equal x <= y
> Greater than x > y
>= Greater than or equal x >= y

== Equal x == y
=== Strict equal x === y
!= Unequal x != y
!== Strict unequal x !== y

&& Logical and x && y
|| Logical or x || y

= Assignment x = y
+= Assignment x += y
-= Assignment x -= y
*= Assignment x *= y
%= Assignment x %= y
<<= Assignment x <<= y
>>= Assignment x >>= y
>>>= Assignment x >>>= y
&= Assignment x &= y
^= Assignment x ^= y
|= Assignment x |= y

### Next, we will take a look at Assignments within Javascript.

Just follow the buttons to continue the tutorial, Guest