function test(){
var name = "dabao";
console.log(name);
}
test();
console.log(name);
function demo(){
var age= "dabao";
console.log(age);
}
demo();
console.log(age);
when I enter the breakpoint, enter name to print out dabao in the browser, and after the breakpoint ends, the table name function has been executed. Is there any operating mechanism in the input name output "
, or because the variables inside the function cannot be accessed outside the function? I know the result. I just want to know the principle.
add a question, why do the above two pieces of code have the same logic, but get different results?