-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharrowFunction.ts
More file actions
81 lines (58 loc) · 1.42 KB
/
arrowFunction.ts
File metadata and controls
81 lines (58 loc) · 1.42 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
// we can declare same function name
// function hoisting
// anonymous function
// const sum = function (a, b) {
// return a + b;
// }
const sum = (a, b) => a + b;
console.log(sum(1, 2));
const greet = (name) => `Hello ${name}`;
console.log(greet("Yagnesh"));
const user1 = {
fistName: "Yagnesh",
lastName: "Modh",
age: 33,
fullName: (firstName) => {
return `hello ${firstName} ${this.lastName}`;
},
};
console.log(user1.fullName(user1.fistName));
const user2 = {
fistName: "Virat",
lastName: "Kohli",
age: 30,
fullName: function () {
return `${this.fistName} ${this.lastName}`;
},
};
class User {
constructor(firstName, lastName, age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
fullName() {
return `${this.firstName} ${this.lastName}`;
}
}
const user11 = new User("Yagnesh", "Modh", 33);
const user12 = new User("Virat", "Kohli", 30);
console.log(user11);
console.log(user11.fullName());
console.log(user12.fullName());
console.log(user1.fullName());
// var sum = () => {
// return "hacked..."
// }
// console.log(sum());
// named function
// function add(a, b) {
// return a + b;
// }
// function/method overloading will not work in javascript
// function add() {
// return "hacked...."
// }
// console.log(add(1,2));
// create arrow function wich except "name" and designation
// and return My name is "name" and i am "designation"