-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy path7_math_operator.js
82 lines (59 loc) · 1.76 KB
/
7_math_operator.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// In JavaScript, there are several math operators that can be used to perform arithmetic operations on numbers.
// Here are some of the most commonly used math operators:
// + (addition): adds two numbers together or concatenates two strings.
// 👀👀
// const x = 10;
// const y = 5;
// const z = x + y; // 15
// 👀👀
const str1 = "Hello, ";
const str2 = "world!";
const str3 = str1 + str2; // "Hello, world!"
// - (subtraction): subtracts one number from another.
// 👀👀
// const x = 10;
// const y = 5;
// const z = x - y; // 5
// * (multiplication): multiplies two numbers together.
// 👀👀
// const x = 10;
// const y = 5;
// const z = x * y; // 50
// / (division): divides one number by another.
// 👀👀
// const x = 10;
// const y = 5;
// const z = x / y; // 2
// % (modulus): returns the remainder of a division operation.
// 👀👀
// const x = 10;
// const y = 3;
// const z = x % y; // 1
// ++(increment): increments a number by 1.
// let x = 10;
// x++; // 11
// --(decrement): decrements a number by 1.
// 👀👀
// let x = 10;
// x--; // 9
// It's worth noting that these operators can be combined and used in more complex expressions.
const x = 10;
const y = 5;
const z = (x + y) * 2; // 30
// In this example, the parentheses are used to ensure that the addition operation is performed before the multiplication operation.
function mathOperators(num1, num2) {
let sum = num1 + num2;
let difference = num1 - num2;
let product = num1 * num2;
let quotient = num1 / num2;
console.log(`Sum: ${sum}`);
console.log(`Difference: ${difference}`);
console.log(`Product: ${product}`);
console.log(`Quotient: ${quotient}`);
}
mathOperators(10, 5);
// Output:
// Sum: 15
// Difference: 5
// Product: 50
// Quotient: 2