javascript - Window.onload Scope -
let's have following code:
var x; window.onload = function(){ x=4; }; console.log(x);
the console doesn't output 4, undefined.
does know how able access changed x variable outside of window.onload function?
thanks in advance!
this has javascript's async behavior. console.log
doesn't happen after window.onload
has fired. they're separate events. if want output x, need
var x; window.onload = function(){ x=4; console.log(x); };
Comments
Post a Comment