0

Came across this question recently the output of the code mentioned below is JavaScript curious how .


var name = "JavaScript"
function foo() {
    name = "Developer";
    return;
    function name() {
    }
}
foo();
console.log(name) //Javascript
WaysToGo
  • 331
  • 3
  • 7
  • Correctly formatting the code might help alleviate your confusion. – Etheryte Nov 09 '19 at 17:16
  • 1
    Possible duplicate of [Javascript function scoping and hoisting](https://stackoverflow.com/questions/7506844/javascript-function-scoping-and-hoisting) – WaysToGo Nov 09 '19 at 17:19
  • 3
    This has to do with function hoisting. The `name` function inside `foo` is implicitly moved to the top, so the inner `name` "variable" is actually a reassignment of the reference that points to the empty function. – glhrmv Nov 09 '19 at 17:20

0 Answers0