Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

82
Views
weird behavior await running without async

I was running firebase when I saw a strange behavior which I am unable to understand. My html looks like this:

<script src="https://www.gstatic.com/firebasejs/8.2.6/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.6/firebase-firestore.js"></script>
<script type="module">

// Import the functions you need from the SDKs you need
import { initializeApp, } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-analytics.js";
import { getFirestore, collection, getDocs, addDoc } from 'https://www.gstatic.com/firebasejs/9.0.2/firebase-firestore.js';
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

const firebaseConfig = { ... } //firebase config
  // Initialize Firebase
    const app = initializeApp(firebaseConfig);
    const analytics = getAnalytics(app);
    const db = getFirestore(app);
    const querySnapshot = await getDocs(collection(db, "location")); *** //await is running without async! ***
    console.log(querySnapshot)
    querySnapshot.forEach((doc, index) => { 
         // do something with doc
         *** // index always returns undefined! ***

    } 

Problem 1: Async running without await.
Problem 2: Index is undefined after reading and iterating data from firebase. Please help as I studied js for more than a year and I feel like a complete newbie now.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Thank You Bergi (Profile): It is indeed a top level await (a feature in moduleJS).

Read more about it here: https://v8.dev/features/top-level-await

Thanks! Dharamraj (Profile) => querySnapshot.docs.forEach() index works perfectly fine now.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!