-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5 arithmetic.js
More file actions
57 lines (43 loc) · 1.38 KB
/
5 arithmetic.js
File metadata and controls
57 lines (43 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
JavaScript Arithmetic Operators
Arithmetic operators are used to perform arithmetic on numbers:
Operator Description
+ Addition
- Subtraction
* Multiplication
** Exponentiation (ES2016)
/ Division
% Modulus (Division Remainder)
++ Increment
-- Decrement
*/
let x = 5;
let y = 2;
let z = x + y;
console.log("x+y ",z);
z = x - y;
console.log("x-y ",z);
z = x * y;
console.log("x*y ",z);
z = x / y;
console.log("x/y ",z);
z = x ** y;
console.log("x**y ",z);
z = x % y;
console.log("x%y ",z);
z = --x + ++y;
console.log("--x + ++y ",z);
z = x++ + y--;
console.log("x++ + y-- ",z);
/*
**********Operator Precedence
Operator precedence describes the order in which operations are performed in an arithmetic expression.
Is the result of example above the same as 150 * 3, or is it the same as 100 + 150?
Is the addition or the multiplication done first?
As in traditional school mathematics, the multiplication is done first.
Multiplication (*) and division (/) have higher precedence than addition (+) and subtraction (-).
And (as in school mathematics) the precedence can be changed by using parentheses:
When using parentheses, the operations inside the parentheses are computed first.
When many operations have the same precedence (like addition and subtraction), they are computed from left to right:
*/
let xx = 100 + 50 * 3;