-
Notifications
You must be signed in to change notification settings - Fork 13
/
08-js-operators.html
154 lines (101 loc) · 3.54 KB
/
08-js-operators.html
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>JS operators</title>
</head>
<body>
<h1>JS operators</h1>
<script>
// PRIRAZOVACI OPERATORY (assignment)
x = 10;
y = x;
console.log(y); //10
// prirazeni se scitanim
x = x + 20;
//nebo x += 20
console.log(x); //30
// prirazeni se odcitanim
x = x - 20;
//nebo x -= 20
console.log(x); //10
// prirazeni s nasobenim
x = x * 5;
//nebo x *= 5
console.log(x); //50
// prirazeni s delenim
x = x / 10;
//nebo x /= 10
console.log(x); //5
// prirazeni se zbytkem
x = x % 3;
//nebo x %= 3
console.log(x); //2
// exponencialni prirazeni
// x = x **3; // NEFUNGUJE V ECMASCRIPT 6, POUZE NAVRH DO ECMA 7
// viz https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Assignment_Operators#Exponentiation_assignment
//nebo x **= 3
//console.log(x); //27
// SROVNAVACI OPERATORY (comparison)
// equal, operandy jsou stejne
console.log("7" == 7); //true
//not equal, operandy nejsou stejne
console.log(3 != 7); //true
// strict equal, operandy jsou stejne a navic stejneho typu
console.log("7" === 7); //false, NENI STEJNY DATOVY TYP
// strict equal, operandy jsou stejne a navic stejneho typu
console.log(3 !== 7); //true
// greater than, vetsi nez
console.log(7 > 3); //true
// greater or equal, vetsi nebo rovno nez
console.log(7 >= 3); //true
// less than, mensi nez
console.log(7 < 7); //false
// less or equal than, mensi nebo rovno nez
console.log(7 <= 7); //true
// ARITMETICKE OPERATORY
console.log( 3 + 4 );
console.log( 7 - 4 );
console.log( 3 * 4 );
console.log( 3 / 4 );
console.log( 5 % 2 ); //1, modulo, posledni zbytek po celociselnem deleni
x = 5;
console.log (x++); //increment, 5, VYPIS 5 A TEPRVE POTOM ZVEDNI HODNOTU O JEDNICKU
x = 5;
console.log (++x); //increment, 6, ZVEDNI HODNOTU O JEDNICKU A PAK VYPIS
x = 5;
console.log (x--); //decrement, 5, VYPIS 5 A TEPRVE POTOM ZMENSI HODNOTU O JEDNICKU
x = 5;
console.log (--x); //decrement, 4, ZMENSI HODNOTU O JEDNICKU A PAK VYPIS
// LOGICKE OPERATORY
yes = true;
no = false
// AND
console.log( yes && yes ); //true, and, plati zaroven oba operandy? ANO
console.log( yes && no ); //false, and, plati zaroven oba operandy? NE
console.log( no && no ); //false, and, plati zaroven oba operandy? NE
// OR
console.log( yes || yes ); //true, or, plati alespon jeden operand? ANO
console.log( yes || no ); //true, or, plati alespon jeden operand? ANO
console.log( no || no ); //false, or, plati alespon jeden operand? NE
// NOT
console.log( !no ); //true, not, neplati? ANO, neplati
console.log( !yes ); //false, not, neplati? NE, neplati
console.log( !no && yes ); //true, not and, otoci hodnotu no a vysledek je stejny jako yes && yes
console.log( !no && !no ); //true, not and, otoci hodnotu no a vysledek je stejny jako yes && yes
console.log( !yes && !yes ); //false, not and, otoci hodnotu yes a vysledek je stejny jako no && no
console.log( !yes || yes || !no || no ); //true, plati alespon 1 operand, je jedno, jak je to dlouhe, vyhodnocovani se zastavi u prvniho true
//RETEZCOVE OPERATORY
a = "ahoj"
console.log(a + 'svete' ); //ahojsvete, a = ahoj
console.log(a += 'svete' ); //ahojsvete, a = ahojsvete
// TERNARNI OPERATORY
// podminka ? hodnota1 : hodnota2
// v praxi se docela pouzivaji
// podminka operandu
a = 10
console.log(a == 10 ? 'oh yes!!!' : 'nooo!'); //vrat oh yes!!!, pokud je a == 10, jinak vrat nooo!
</script>
<h2>See the results in JS console in your browser</h2>
</body>
</html>