-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrowfun.js
46 lines (31 loc) · 1010 Bytes
/
Arrowfun.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
//this : it refers to the current context
// const user={
// username:"hitesh",
// price:99,
// welcomeMessage: function(){
immediateInvokedfunction// console.log(`${this.username}, welcome to website`);
// console.log(this);
// }
// }
// user.welcomeMessage()
// user.username="sam"
// user.welcomeMessage()
//console.log(this);//{}
// in node environment global object in empty {} but if you run console.log(this) on browser then you will get "window" as an output
//function using arrow function
const chaii=()=>{
console.log("I am called");
}
chaii()
//below is syntax of arrow function
//const anyname=()=>{}
const addtwo=(n1,n2)=>{
return n1+n2
}
console.log(addtwo(4,3))
//using implicit return that is if we use curly braces then we have to write return keyword explicity
const addno=(n1,n2)=>(n1+n2)
console.log(addno(5,6));
//returning objects
const obj1=()=>({username:"akshay",age:22})
console.log(obj1());//{ username: 'akshay', age: 22 }