-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_6_js6.js
More file actions
67 lines (50 loc) · 1.31 KB
/
3_6_js6.js
File metadata and controls
67 lines (50 loc) · 1.31 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
58
59
60
61
62
63
64
65
66
67
"use strict";
chapter("Javascript 6+ features");
section("Template strings");
example("`10 + 20 = ${10 + 20}`");
example("`Random value: ${Math.random()}`");
example("`Hello ${`from ${Math.random()}`.toUpperCase()}`");
section("Sets");
const set = new Set().add(1).add(2).add(1);
example("set");
example("set.size");
example("set.has(1)");
example("set.has(3)");
example("for (const value of set.values()) { println(value); }");
section("Maps");
const mp = new Map().set("hello", 1).set("bye", 2).set("hello", 3);
example("mp");
example("mp.size");
example("mp.has('hello')");
example("mp.get('hello')");
example("mp.get('hello2')");
example("for (const entry of mp.entries()) { println(entry); }");
example("for (const key of mp.keys()) { println(key); }");
example("for (const value of mp.values()) { println(value); }");
example("mp.delete('hello')");
example("mp.get('hello')");
example("mp.has('hello')");
section("Iterators");
function* range(start, end) {
while (start < end) {
yield start;
start++;
}
}
example("range(3, 6)");
for (const i of range(3, 6)) {
println(`\ti = ${i}`)
}
function* fibs(a = 1, b = 1) {
while (true) {
yield a;
[a, b] = [b, a + b]
}
}
example("fibs()");
for (const i of fibs()) {
println(i);
if (i === 13) {
break;
}
}