I am kind of novice in JavaScript, I really don't quite understand why the below code return 1
instead of 10
:
var a = 1;
function b() {
a = 10;
return;
function a() {}
}
b();
alert(a);
The running code: http://jsfiddle.net/smMtU/
If I rem the line function a() {}
, it returns 10
as expected. This code got from this post to explain the concept scoping and hoisting in JavaScript. Maybe I am missing something while reading this post?
Please anyone could point out the concept behind this code?