forked from HackYourFuture/JavaScript2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhoisting.js
More file actions
124 lines (108 loc) · 2.09 KB
/
hoisting.js
File metadata and controls
124 lines (108 loc) · 2.09 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
{
'use strict'
/*
* Function Hoisting
*/
// Exercise #1
// abc();
// function abc() {
// console.log('INSIDE FUNCTION ABC');
// }
// xyz();
// var xyz = function() {
// console.log('INSIDE FUNCTION XYZ');
// };
// Exercise #2
// function foo1() {
// function bar() {
// return 3;
// }
// return bar();
// function bar() {
// return 8;
// }
// }
// console.log(foo1());
// Exercise #3
// function foo2(){
// var bar = function() {
// return 3;
// };
// return bar();
// var bar = function() {
// return 8;
// };
// }
// console.log(foo2());
// Exercise #4
// console.log(foo3());
// function foo3(){
// var bar = function() {
// return 3;
// };
// return bar();
// var bar = function() {
// return 8;
// };
// }
// Exercise #5
// function foo4(){
// return bar();
// var bar = function() {
// return 3;
// };
// var bar = function() {
// return 8;
// };
// }
// console.log(foo4());
/*
* Variable Hoisting
*/
// Exercise #1
// arr = [10,20,30];
// console.log(arr);
// var arr;
// console.log(obj);
// var obj = { a: 10, b: 20 };
// Exercise #2
// console.log(num1);
// let num1 = 10;
/*
* Variable and Function hoisting combined
*/
// Exercise #1
// function parent() {
// function hoisted() {
// return "I'm a function";
// }
// hoisted = "I'm a variable";
// return hoisted();
// }
// console.log(parent());
// Exercise #2 (Tricky)
// function parent() {
// var hoisted = "I'm a variable";
// function hoisted() {
// return "I'm a function";
// }
// return hoisted();
// }
// console.log(parent());
// Exercise #3
// function func() {
// function foo() { };
// return foo;
// foo = 10;
// foo = 1;
// }
// console.log(typeof func());
// Exercise #4
// function func() {
// return foo;
// foo = 10;
// var foo = 1;
// function foo() { };
// }
// console.log(typeof func());
}