title: Data not working in global scope but in local scope
body: <p>I have been trying to make an e-commerce website and in that almost all things are done except for the database part. In which I have to fetch the data from firebase and use it in the products section.
  I have fetched the data in local variables, however I want to store the data in a global scoped object, but it is not working.
  So what I basically want is I want to fetch the data from firebase(DONE) and store it in global scope object(PENDING) so that I can use this object in other .js files.
  Any kind of idea/advice/help/suggestion in more than welcomed!!
  Thanks in advance!</p>
  <p>This is my code:
  <a href="https://jsfiddle.net/kumartanwar123/gseh4coq/" rel="nofollow noreferrer">https://jsfiddle.net/kumartanwar123/gseh4coq/</a></p>
  <p><strong>OR</strong></p>
  <pre><code>import { initializeApp } from &quot;https://www.gstatic.com/firebasejs/9.6.7/firebase-app.js&quot;;
  import { getAnalytics } from &quot;https://www.gstatic.com/firebasejs/9.6.7/firebase-analytics.js&quot;;
  // GLOBAL VARIABLES
  var name, images, prices;
  const firebaseConfig = {
    apiKey: &quot;--&quot;,
    authDomain: &quot;--&quot;,
    databaseURL: &quot;--&quot;,
    projectId: &quot;round-device-336118&quot;,
    storageBucket: &quot;round-device-336118.appspot.com&quot;,
    messagingSenderId: &quot;--&quot;,
    appId: &quot;--&quot;,
    measurementId: &quot;--&quot;,
  };
  const app = initializeApp(firebaseConfig);
  firebase.initializeApp(firebaseConfig);
  class firebase_class {
    constructor(Images, Prices, Name) {
      this.Images = Images;
      this.Prices = Prices;
      this.Name = Name;
    }
  }
  // FIREBASE DATA FETCH
  firebase
    .database()
    .ref(&quot;Practice&quot;)
    .on(&quot;value&quot;, function (all_data) {
      all_data.forEach(function (current_data) {
        name = Object.keys(current_data.val().Name).map(
          (keys) =&gt; current_data.val().Name[keys]
        );
        //In this if I use console.log(name) then it is working just fine, but not in outside the function.
        images = Object.keys(current_data.val().Images).map(
          (keys) =&gt; current_data.val().Images[keys]
        );
        prices = Object.keys(current_data.val().Prices).map(
          (keys) =&gt; current_data.val().Prices[keys]
        );
      });
    });
  let firebase_object = new firebase_class(images, prices, name);
  </code></pre>