-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
126 lines (111 loc) · 2.04 KB
/
main.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
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
/*Hoisting means that variable declarations and function expressions (but not assignments)
are hoisted to the top of their scope, and declared before anything other code runs.*/
/*INSTRUCTIONS:
1: Fill in prediction with what you think will happen.
2: Uncomment the invocation, and run the code.
3: Write in actual what really happened.
If it matches, GREAT! If not, review tomorrow! */
function problemOne() {
console.log(num);
};
//problemOne();
//Prediction:
//Actual:
function problemTwo() {
console.log(num);
var num;
};
//problemTwo();
//Prediction:
//Actual:
function problemThree() {
console.log(num);
var num;
num = 6;
};
//problemThree();
//Prediction:
//Actual:
function problemFour() {
num = 6;
console.log(num);
var num;
};
//problemFour();
//Prediction:
//Actual:
function problemFive() {
var x = 1;
console.log(x + " " + y);
var y = 2;
};
//problemFive();
//Prediction:
//Actual:
function problemSix() {
function bar() {
return 3;
}
console.log(bar())
function bar() {
return 8;
}
};
//problemSix();
//Prediction:
//Actual:
function problemSeven() {
var bar = function() {
return 3;
}
console.log(bar())
var bar = function() {
return 8;
}
};
//problemSeven();
//Prediction:
//Actual:
function problemEight() {
var a = 1;
function b() {
a = 10;
return;
function a() {}
}
b();
console.log(a);
}
//problemEight();
//Prediction:
//Actual:
function problemNine() {
var x = 1;
console.log(x + " " + y);
let y = 2;
};
//problemNine();
//Prediction:
//Actual:
function problemTen() {
var x = 1;
console.log(x + " " + y);
const y = 2;
};
//problemTen();
//Prediction:
//Actual:
function problemEleven() {
function parent() {
var hoisted = "I'm a variable";
function hoisted() {
return "I'm a function";
}
return hoisted();
}
console.log(parent());
};
//problemEleven();
//Prediction:
//Actual:
// S/O to this great article! -> https://medium.freecodecamp.org/function-hoisting-hoisting-interview-questions-b6f91dbc2be8