-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
64 lines (64 loc) · 1.24 KB
/
main.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
"use strict";
let id = 5;
id = 7;
let productIds = [];
// Tuple
let person = [1, 'Tim', true];
// Tuple array
let employee;
employee = [
['foo', true],
['bar', false],
['baz', false],
];
// Union
let offer = 2;
offer = '2';
offer = false;
const user = {
id: '500',
name: 'Foo Bar',
};
// Type assertion
let cid = 1;
let customerId = cid;
customerId = 6;
// Functions
const sum = (x, y) => {
return x + y;
};
const myMessage = (messasge) => {
console.log(messasge);
};
myMessage('true');
const memberData = {
id: 39138281,
name: 'Tim Tam',
paid: false,
};
class basketballPlayer {
constructor(jerseyNo, jerseyName) {
this.jerseyNo = jerseyNo;
this.jerseyName = jerseyName;
}
playsFor() {
return `${this.jerseyName} plays basketball`;
}
}
const sc30 = new basketballPlayer(30, 'Curry');
console.log(sc30.playsFor());
// Subclass
class Position extends basketballPlayer {
constructor(id, name, position) {
super(id, name);
this.position = position;
}
}
const kb24 = new Position(24, 'Kobe', 'SG');
console.log(kb24.position);
// Generics
const getArray = (items) => {
return new Array().concat(items);
};
let numArray = getArray([1, 2, 3, 4]);
numArray.push(1);