-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhoisting.js
More file actions
46 lines (38 loc) · 1001 Bytes
/
hoisting.js
File metadata and controls
46 lines (38 loc) · 1001 Bytes
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
// hoisting();
// console.log("--->>" + i);
// // This is function delcaration
// function hoisting() {
// console.log(hoist);
// var what = "Variables and function declarations";
// console.log("What is hoisted?" + what);
// var hoist = "to lift or raise up";
// console.log("Hoist means " + hoist);
// }
// var i;
// //This is function expression
// const addNums = (a, b) => {
// console.log("Added numbers is " + (a + b));
// };
// addNums(4, 5);
// var globalVar = "global";
// var outerVar = "outer";
// function outerFunc(outerParam) {
// function innerFunc(innerParam) {
// console.log(globalVar, outerParam, innerParam);
// }
// return innerFunc;
// }
// const x = outerFunc(outerVar);
// outerVar = "outer-2";
// globalVar = "guess";
// x("inner");
const arrFuncs = [];
for (let i = 0; i < 5; i++) {
console.log(i);
arrFuncs.push(function() {
return i;
});
}
for (let j = 0; j < arrFuncs.length; j++) {
console.log(arrFuncs[j]()); // all logs "5"
}