-
Notifications
You must be signed in to change notification settings - Fork 0
/
hoisting.js
48 lines (35 loc) · 1.06 KB
/
hoisting.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
// What variable and function hoisting is and how it works.
// R: The order of assign functions and variables. You cannot call a function before his declaration
// Function expressions, like: "var a = function(..." never hoists to top;
// Function declarations, like "function (..." goes to the top hoisted, so, you can call the function before the declaration
// // tab 1
// console.log(color); // Undefined
// var color = "blue";
// console.log(color); // ok
// //tab 2
// var color;
// console.log(color); // Undefined
// color = "blue";
// console.log(color); // ok
// tab 3
// console.log(getProduct(2, 3));
// var getProduct = function (num1, num2) {
// return num1 * num2;
// };
// console.log(getProduct(2, 3));
// tab 4
// console.log(getProduct(2, 3)); // Declarative function here, gonna works
// function getProduct(num1, num2) {
// return num1 * num2;
// }
// tab 5
var globalVar = 'global';
(function () {
var name = 'Jen';
var getAge = function () {
return '30';
};
function getState() {
return 'Delaware';
}
})();