console.log(a);
var a = "a";
function b(){
console.log(a);
var a = "a1";
console.log(a);
}
b();
I forgot that functions also hoisted, that's why second log will clouser the undefined value of a.
2018 Jan 23, 2:13:34 PM
undefined undefined a1 - it's right answer without 'use strict' with 'use strict' - Uncaught SyntaxError: Unexpected identifier and stopping the script execution
2017 Apr 2, 10:33:32 AM
Isnt var a already global when the first console.log gets executed ? How is it undefined ?
2016 Nov 29, 5:35:05 PM
Login in to like
Login in to comment