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

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -