-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchap6.js
More file actions
130 lines (113 loc) · 2.01 KB
/
chap6.js
File metadata and controls
130 lines (113 loc) · 2.01 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//Function and Execution
//Simple function
/*
function addtocart(product)
{
console.log(`${product} is added to cart.`);
}
addtocart("Pen");
addtocart("Tablet");
addtocart("Shoes");
*/
//Anonymous function
/*
let sum=function()
{
console.log(2+9);
}
sum(); //calling the function
*/
//Higher order function
/*
//Passing function as argument
function getclicked(clicked)
{
clicked();
}
getclicked(function() //function calling
{
console.log("i am clicked");
}
)
//returning a function as a value from that
function returnFunction()
{
return function()
{
console.log("returning");
}
}
//calling
//1
returnFunction()();
//2
let rf=returnFunction();
rf();
*/
//Arrow function
/*
let print=()=>
{
console.log("hello friends!!");
}
print(); //call the function
//Other way to define Arrow fn.
let op=()=>console.log("this is output");
op();
*/
//using arrow in addition
/*
let sum=(a,b)=>
{
return a+b;
}
//or
let add=(a,b)=>a+b;
console.log(add(10,5));
*/
//Immediately Invoked Function Expression (IIFE)
/*
(function sub()
{
console.log(9-4);
}
)
() // immediate call of fn.
//IIFE as arrow fn.
(() => {
console.log(2 * 9);
})();
*/
//other declaration of functin and variable
/*
let a=10;
function hello()
{
a=20;
console.log(a);
}
hello(); //will give o/p 20
console.log(a); // will also give o/p 20 bcz in the compiler value of a is updated but if we define a of fn. differently then both will different
// see here
let b=20;
function op()
{
var b=30;
console.log(b);
}
op(); //o/p will be 30
console.log(b); // o/p will be 20
*/
//Learning execution context and its type
//To understand the execution and it's parts :- 1.memory creation phase and 2.execution phase
/*
var l=20;
var w=30;
function calculate(length,width)
{
let area=length*width;
return area;
}
var rectangle=calculate(l,w);
console.log(rectangle);
*/