-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
78 lines (78 loc) · 1.77 KB
/
app.js
File metadata and controls
78 lines (78 loc) · 1.77 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
"use strict";
const person = {
name: 'shubham',
age: 40,
};
console.log(person.name);
const students = ['shubham', 'shivam', 5];
let i = 0;
const data = ['shubham', 19]; // Tuple is for defining data structure
do {
console.log(students[i]);
i++;
} while (i < students.length);
// Understanding Enums Typescript
var Role;
(function (Role) {
Role[Role["ADMIN"] = 0] = "ADMIN";
Role[Role["READ_ONLY"] = 1] = "READ_ONLY";
Role[Role["AUTHOR"] = 2] = "AUTHOR";
})(Role || (Role = {}));
;
// 0 , 1, 2
const humans = {
name: 'shubham',
role: Role.READ_ONLY,
};
if (humans.role === Role.ADMIN) {
console.log("Is admin");
}
else {
console.log('Not admin');
}
;
// Any type
// const students: any[] = ['shubham', 'shivam', 5];
// ------------> Union Type
function combine(input1, input2, input3) {
let result;
if (input1 === 'number' && input2 === 'number') {
result = input1 + input2;
}
else {
result = input1.toString() + input2.toString();
}
;
return result;
}
;
const combineAges = combine(30, 20, 'negi');
const combineNames = combine('Max', 'Sam', 'suvi');
const TypeAlises = 'suvi';
// ----------------> Function return and Voids
function setReturnType(n1, n2) {
return n1.toString() + n2.toString();
}
// Function that doesn't return anything call Void Functions
function voidFunction(num) {
console.log('Result: ' + num);
}
;
// undefined is a type in TypeScript
// Function Types
function add(n1, n2) {
return n1 + n2;
}
;
const functionType = voidFunction;
let addValues;
addValues = add;
// Unknown Type
let userInput;
userInput = 'suvi';
// The Never Type
function generateError(message, code) {
throw { message: message, errorCode: code };
}
;
generateError('An Error Occurred! ', 500);