variable no accessible after a Firebase call [duplicate]
问题 This question already has answers here : Passing variable in parent scope to callback function (3 answers) Closed 4 years ago . I'm using Firebase to access to same data, but i can't use the data out of the function used to access it. How i can make a console log of the data just accessed instead of the initial value? var whatNeed = 'hello'; gameData = new Firebase('https://thegame.firebaseio.com/gameData'); gameData.on("value", function(snapshot) { var data = snapshot.val(); whatNeed = data