How is the output for below snippets - function.
console.log(typeof foo);
function foo() {
  return "bar";
}
var foo = "bar";
function foo() {
  return "bar";
}
var foo;
console.log(typeof foo);
Shouldn't it be undefined due to var foo?
How is the output for below snippets - function.
console.log(typeof foo);
function foo() {
  return "bar";
}
var foo = "bar";
function foo() {
  return "bar";
}
var foo;
console.log(typeof foo);
Shouldn't it be undefined due to var foo?
 
    
    var foo redundantly declares the variable and doesn't assign anything to it.
It doesn't explicitly assign undefined so it doesn't overwrite the existing function value with undefined.
