-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTutorial.js
More file actions
85 lines (85 loc) · 2.23 KB
/
Tutorial.js
File metadata and controls
85 lines (85 loc) · 2.23 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"use strict";
// // working with type annotations
let id = 5;
let company = "Acme limited";
let isPublished = true;
let arr = [1, 2, 3, 4, 5];
let x = "Anas";
let val = ["Anas", 22, true,];
const concatenate = (a, b) => {
return a + b;
};
concatenate("Hello", "World!");
concatenate("5", "10");
const User = {
id: 2,
name: "Anas",
greet(message) {
console.log(message);
}
};
User.greet("Hello!");
if (!User.age) {
console.log("No Age available for user");
}
else {
console.log(User.age);
}
const printID = (id) => {
console.log("ID" + id);
};
printID("1abdc");
printID(22);
const signedContract = (employee) => {
console.log(employee.name + " " + "with email" + " " + employee.email + " " + "Signed Contract and his credit Score is" + " " + employee.creditScore);
};
signedContract({ name: "Anas", creditScore: 1272, id: 34, email: "anas@gmail.com" });
// enums practise
var loginError;
(function (loginError) {
loginError["Unauthorized"] = "User is not authorized";
loginError["noUser"] = "User doesn't exist";
loginError["wrongCredentials"] = "InCorrect email or password";
loginError["internal"] = "Internal Error";
})(loginError || (loginError = {}));
const printError = (error) => {
if (error == loginError.Unauthorized) {
console.log(loginError.Unauthorized);
}
else if (error == loginError.noUser) {
console.log(loginError.noUser);
}
else if (error == loginError.wrongCredentials) {
console.log(loginError.wrongCredentials);
}
else {
console.log(loginError.internal);
}
};
printError(loginError.Unauthorized);
printError(loginError.noUser);
printError(loginError.wrongCredentials);
printError(loginError.internal);
// Generic types practise
class StorageContainer {
constructor() {
this.contents = [];
}
addItem(item) {
this.contents.push(item);
}
getItem(idx) {
return this.contents[idx];
}
}
const usernames = new StorageContainer();
usernames.addItem("Anas");
usernames.addItem("Abbas");
console.log(usernames.getItem(1));
const age = new StorageContainer();
age.addItem(22);
age.addItem(25);
age.addItem(34);
console.log(age.getItem(0));
console.log(age.getItem(1));
console.log(age.getItem(2));