Hi I am trying to assign var foo to a value within my firebase databse, however this just gives me undefined when using console log on foo.
var foo;
firebase.database().ref(`/topics/lec1`).once('value').then(function(snapshot) {
foo = snapshot.val();
console.log(foo);
});
console.log(foo); //undefined
then? if not, then it's okay. You are logging foo before it is set byfirebasesince it isasynchronousthen(), since firebase is asynchronous.