JavaScript variables scope.
the global variable "argument" is getting change in local scope but again returning to original value outside the function scope in console.log(attachments) Firebase/JavaScript code: var attachments="a"; function submitForm(e){ e.preventDefault(); var name = $('#name').val(); var email = $('#email').val(); // Created a Storage Reference with root dir var storageRef = firebase.storage().ref(); // Get the file from DOM var file = document.getElementById("files").files[0]; // Create a reference to the file we want to download var starsRef = storageRef.child(file.name); // Get the download URL starsRef.getDownloadURL().then(function(url) { attachments = url; }).catch(function(error) { // Handle any errors }); console.log(attachments); //OUTPUT "a" saveMessages(name,email,queryType,message,attachments); }