-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path24_Arrow_Function.js
More file actions
57 lines (28 loc) · 1.11 KB
/
24_Arrow_Function.js
File metadata and controls
57 lines (28 loc) · 1.11 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
function chai() {
let username = "tarun"
console.log(this.username)
}
chai()
const bread = function(){
let companyName = "amul"
console.log(this.companyName)
}
bread() // gives the same result for both type pf function declaration.
// ++++++++++++ ARROW FUNCTION +++++++++++++++++
const cokkies = () => { // Arrow function : remove the function keyword with =>
let companyName = "sugarfree"
console.log(this.companyName)
}
cokkies()
// 1} Basics : Explicite return : return keyword and {} is used.
const addTwo = (num1 , num2) => {
return num1 + num2
}
console.log(addTwo(5,75))
// 2} Implicite return : curely braket and return is not used and function is defined in only one line
const addThree = (num1, num2, num3) => ( num1 + num2 + num3 )
console.log(addThree(5,75,60))
// {} use kiya to return keyword likhna he padega. varna jarurat nhi hai.
// 3} Note :
const combine = (num1, num2) => ( {username : "tarun"}) // fucntion is returning an object here
console.log(combine(5,75)) // kuch bhi vakue de do no matter because function to object return kr raha hai.