forked from 4iz268/cviceni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
08-js-control-flows.html
98 lines (63 loc) · 1.47 KB
/
08-js-control-flows.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>JS control flows</title>
</head>
<body>
<h1>JS control flows</h1>
<script>
//IF ELSE
// boolean
var yesno = true;
//IF ELSE
if (yesno) {
console.log('yes');
} else {
console.log('yes');
}
//IF ELSE
// string
var love = "i felt in love with...";
if (love) {
console.log('heaven');
} else {
console.log('hell');
}
// IF - ELSE IF - ELSE
// number
var magic = 7;
if (magic==7) {
console.log('seven');
} else if (magic==5) {
console.log('hell');
}
// SWITCH - CASE
// pokud se nepouzije break, vyraz se vyhodnocuje vicekrat
// samozrejme jde nahradit if-else if-else
switch (magic) {
case 7:
console.log('switch case 7')
//break;
case (magic > 1):
console.log('switch case magic>1')
//break;
default:
console.log('default')
}
// TRY - CATCH - FINALLY
// zachytavani vyjimek
try {
throw "bogus"; // vyhodi se vyjimka (at uz to udelame my, nebo nase aplikace)
} catch(e) { // zachytime vyjimku
console.log('exception catched'); //neco udelame
} finally {
// finally se provede VZDY, at uz nastala nejaka vyjimka, nebo ne
// pouziva se typicky na uzavirani socketu, spojeni do databaze, uzavreni pointeru na soubor, apod.
// zkuste zakomentovat throw v radku nahore, uvidite, ze se tohle provede vzdy
console.log('finally');
}
</script>
<h2>See the results in JS console in your browser</h2>
</body>
</html>