-
Notifications
You must be signed in to change notification settings - Fork 0
/
variables.js
66 lines (66 loc) · 1.57 KB
/
variables.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
66
// variable declarations
// FORMAT: let variable: type = value;
var myname = "Tomiwa";
var age = 10;
var winner = true;
var sum = age + age;
// ARRAY
// FORMAT: let arrayName: type[] = [];
var names = [];
names.push("John");
names.push("Tomiwa");
names.push("BlackDev");
console.log(names);
// TUPLE - is a special structure in TS that can hold as many
// -values as needed
// FORMAT: let tupleName: [type, type, type] = [];
var person = ["Tobi", 19, true];
// FUNCTIONS
function mySum(a, b) {
return a + b;
}
var result;
function calc(a, b) {
result = a + b;
}
// optional parameter- to declare a function with optional
// parameter you use "?"
function speak(name, age) {
return name + " " + age;
}
// CLASSES
var Person = /** @class */ (function () {
function Person(firstname, lastname) {
this.fullname = firstname + " " + lastname;
}
Person.prototype.getName = function () {
return this.fullname;
};
return Person;
}());
var person1 = new Person("Adetomiwa", "Adesanya");
function infor(person) {
return person.age;
}
var Student = /** @class */ (function () {
function Student(a, b, c) {
this.name = a;
this.age = b;
this.good = c;
}
return Student;
}());
var Lion = /** @class */ (function () {
function Lion() {
this.roar = 'roaarrrrr';
}
return Lion;
}());
var Tiger = /** @class */ (function () {
function Tiger() {
this.roar = 'ROAARRRRRRR';
}
return Tiger;
}());
//Tiger and Lion implement the panthera interface, which mean
// Tiger and Lion must have a roar property