1/*Hoisting is JavaScript's default behavior of moving
2all declarations to the top of the current scope (script or function).
3Be carefull that only declaration gets hoisted NOT the initialitations*/
4
5var x = 5;
6alert("x is = "+x+". y is = "+y);//result => x is = 5. y is = undefined.
7var y = 7;
8
9/*
10note that the code doesn't produce the error "y is not defined" like
11it would if we would omit y. It executes but not in the way you would want.
12*/
13
1console.log(functionBelow("Hello"));
2function functionBelow(greet) {
3 return `${greet} world`;
4}
5console.log(functionBelow("Hi"));
1console.log(num); // Returns 'undefined' from hoisted var declaration (not 6)
2var num; // Declaration
3num = 6; // Initialization