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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -