I was reading a tutorial on Javascript basics & how it is different from other languages like C, C++ in terms of having function-level scope rather than block-level scope, but, came across this script which got me confused!
So, Basically:
- I want to know how does outcome of the following code comes to be '1'?
And exactly what is the role of function a() {} ? I mean its never called and in
function b() {}
also there's a return statement before its declaration. But if i change the function name , the alert gives the value '10'.Why?<script> var a = 1; function b() { a = 10; return; function a() {} } b(); alert(a); </script>