forked from degranda/jsBasico-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5-hoisting.js
38 lines (21 loc) · 808 Bytes
/
5-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
// Hoisting es cuando las declaraciones de variables y funciones se procesan antes de ejecutar cualquier código, al momento de qe se genere el hosting, las funciones se declarán primero, y despues las variables.
// Qué resultado esperas que nos aparezca si corremos este ejemplo? "undefined"
console.log(miNombre);
var miNombre = "Diego";
// Lo que sucede con el hoisting
var miNombre = undefined;
console.log(miNombre + "soy hoisting");
miNombre = "Diego";
// === Hoisting con funcionts ===
hey();
function hey() {
console.log('Hola ' + miNombre);
};
var miNombre = 'Diego';
// Lo que sucede con hoisting
function hey() { //La función se declara hasta arriba, y después se declaran las variables.
console.log('Hola ' + miNombre);
};
var miNombre;
hey();
miNombre = 'Diego';