var a = "global scope";
function b () {
var a =" local scope";
eval ("console.log (a Magi 1)"); / / local scope
(new Function (", "console.log (a Magne 2)")) (); / / global scope
}
b ();
what is wrong with this code? : ReferenceError: an is not defined
the global variable a will not report an error without var declaration:
a = "global scope";
function b () {
var a =" local scope";
eval ("console.log (console.log)"); / / local scope
(new Function (", "console.log (AM2)")) (); / / global scope
}
b ();
print:
local scope 1
global scope 2