-
Notifications
You must be signed in to change notification settings - Fork 0
/
js-arithmetic-operators.js
138 lines (102 loc) · 2.2 KB
/
js-arithmetic-operators.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//JavaScript Aritmetik Operatörler
//Atama Operatörü
let degisken1 = 60;
let degisken2 = degisken1;
let x = 2;
x+=2; console.log(x); //4
x-=4; console.log(x); //-2
x*=5; console.log(x); //10
x/=2; console.log(x); //1
x%=2; console.log(x); //0
x++; console.log(x); //3
x--; console.log(x); //1
//Toplama Operatörü
let degisken1 = 23;
let degisken2 = 37;
let sonuc = degisken1 + degisken2;
document.write(sonuc); //60
// Number + Number -> toplar
1 + 2 // 3
// Boolean + Number -> toplar
true + 1 // 2
// Boolean + Boolean -> toplar
false + false // 0
// Number + String -> birleştirir
5 + "foo" // "5foo"
// String + Boolean -> birleştirir
"foo" + false // "foofalse"
// String + String -> birleştirir
"foo" + "bar" // "foobar"
//Çıkarma Operatörü
let sayi1 = 78;
let sayi2 = 18;
let sonuc = sayi1 - sayi2;
document.write(sonuc); //60
5 - 3 // 2
3 - 5 // -2
"foo" - 3 // NaN
//Çarpma Operatörü
let sayi1 = 20;
let sayi2 = 3;
let sonuc = sayi1 * sayi2;
document.write(sonuc); //60
2 * 2 // 4
-2 * 2 // -4
Infinity * 0 // NaN
Infinity * Infinity // Infinity
"foo" * 2 // NaN
//Bölme Operatörü
let sayi1 = 180;
let sayi2 = 3;
let sonuc = sayi1/sayi2;
document.write(sonuc); //
1 / 2 // 0.5
1.0 / 2.0 // 0.5
2.0 / 0 // Infinity
2.0 / 0.0 // Infinity
2.0 / -0.0 // -Infinity
//Mod (Kalan) Operatörü
let sayi1 = 60;
let sayi2 = 8;
let sonuc = sayi1 % sayi2;
document.write(sonuc);//4
12 % 5 // 2
-1 % 2 // -1
NaN % 2 // NaN
1 % 2 // 1
2 % 3 // 2
-4 % 2 // -0
5.5 % 2 // 1.5
//Üs Alma Operatörü
2 ** 3 // 8
3 ** 2 // 9
3 ** 2.5 // 15.588457268119896
10 ** -1 // 0.1
NaN ** 2 // NaN
2 ** 3 ** 2 // 512
2 ** (3 ** 2) // 512
(2 ** 3) ** 2 // 64
//Artırma Operatörü
// Sonuna yazınca
let x = 3;
y = x++; // y = 3, x = 4
// Önüne yazınca
let a = 2;
b = ++a; // a = 3, b = 3
//Azaltma Operatörü
// Sonuna yazınca
let x = 3;
y = x--; // y = 3, x = 2
// Önüne yazınca
let a = 2;
b = --a; // a = 1, b = 1
//Olumsuzlama Operatörü
let x = 3;
y = -x; // y = -3, x = 3
//Tekil Artı Operatörü
+3 // 3
+"3" // 3
+true // 1
+false // 0
+null // 0
+function(val){ return val } // NaN