function foo(a) {
  function a() {
    return 8;
  }
  return a();
  y = 9;
}
console.log(foo() + " " + y);
This gives an undefined error for variable y.
function foo(a) {
  y = 9;
  function a() {
    return 8;
  }
  return a();
}
console.log(foo() + " " + y);
This prints 8 9 in the browser console.
If we declare a variable without the var keyword than it becomes global variable.
Why first function does not follow the idea?
 
     
    