-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
65 lines (49 loc) · 916 Bytes
/
test.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
// Recursion
function fact(n) {
if (n == 1) {
return 1;
}
return n * fact(n - 1);
}
// Validate
if (fact(6) == 720) {
console.log("fact(6) was correct! (" + fact(6) + ")");
}
else {
console.log("fact(6) was incorrect! (" + fact(6) + ")");
}
// For loops
for (let i = 1; i < 6; i = i + 1) {
console.log(i);
}
// Objects and nested objects
let obj = {
nested: {
func: function() { console.log("Nested function called!") }
},
i: 32
};
// Accessing nested members
obj.nested.func();
// Arrow functions
let test = (arg => { console.log(arg) })("Arrow functions!");
// JSON
console.log(JSON.stringify(obj));
// Classes
class MyClass {
constructor() {
this.property = "Some value";
}
toString() {
return JSON.stringify(this);
}
}
console.log(new MyClass());
const temp = {
a: 1
};
console.log(temp);
// inserts new keys
temp.b = 2;
console.log(temp);
console.log("A,B,C".split(","))