Why do variable in an inner function return nan when there is the same variable name at the inner function...
7
1
What's happening here? I get a different result if I declare a variable after console.log in the inner function I understand that var has a functional scope and inner function can access the variable from their parent
function outer() {
var a = 2;
function inner() {
a++;
console.log(a) //log NaN
var a = 8
}
inner()
}
outer()
function outer() {
var a = 2;
function inner() {
a++;
console.log(a) //log 3
var b = 8
}
inner()
}
outer()
The log returns NaN in the first example and log 3 in the second example
javascript function
share | improve this question
...