javascript - ReferenceError: variable is not defined -
i met issue still don't know causes it.
i have script in page:
$(function(){ var value = "10"; });
but browser says "referenceerror: value not defined". if go browser console , input either
10
or
var value = "10";
either of them can return 10. problem script?
edit:just rid of "var" can solve problem.
it's declared inside closure, means can accessed there. if want variable accessible globally, can remove var
:
$(function(){ value = "10"; }); value; // "10"
this equivalent writing window.value = "10";
.
Comments
Post a Comment