2-10 Creation and hoisting

  • hoisting : before js code is run line by line, js engine set memory space for the variables
  • all variables is initialized to undefined in js

1
2
3
4
5
6
7
8
9
10
11
12

b();
console.log(a);

var a = 'Bello';
function b (){
console.log('called b');
}
/*
called b
undefined
*/
1
2
3
4
5
6
7
8
9
10
11
12

b();
console.log(a);

function b (){
console.log('called b');
}

/*
called b
Error!!
*/