javascript - JS - Set variables value in function but use variable outside of it? -


i need set variables value within function, use outside of function. can done?

$(document).ready(function() {     $(window).scroll(function () {         var myvar = something;     });     console.log(myvar); }); 

yes, need first declare outside of function.

$(document).ready(function() {     var myvar;      $(window).scroll(function () {        myvar = something;     });      console.log(myvar); }); 

just know myvar updated after scroll event triggered. so, console.log log undefined because runs before event runs , sets variable.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -