I was browsing around the internet and came upon this JavaScript function
function foo(){
function bar() {
return 3;
}
return bar();
function bar() {
return 8;
}
}
console.log(foo());
=>8
It's really confusing why this function is returning 8 when it is called. I would assume that this code would run down the contents of the function and stop at return bar();and return 3. What am I missing here?
bar()overwrites the first.