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

132
Views
await reserved word problem at firebase v9

If I use the code as in firebase documentation I get the error await is reserved word

try {
  const docRef = await addDoc(collection(db, "users"), {
  first: "Alan",
  middle: "Mathison",
  last: "Turing",
  born: 1912
});
 console.log("Document written with ID: ", docRef.id)
} catch (e) {
  console.error("Error adding document: ", e);
}

If I use it like this I don't get any error but this doesn't work

async () => {
try {
   const docRef = await addDoc(collection(db, "projects", vm.add.slug), {
    first: "Alan",
    middle: "Mathison",
    last: "Turing",
    born: 1912
  })
  console.log("Document written with ID: ", docRef.id)
} catch (err) {
    console.log("error deleting data:", err)
  }
}

Can anyone help me what do I do wrong.

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

0

As Brian said, in the first example, you're calling await in a function that is not an async one, and in the second try, you've only defined a function that was never called.

My suggestion: Create an async function, and call it where you want, with await.

    const submit = async payload => {
      try {
        const docRef = await addDoc(collection(db, "projects", vm.add.slug), payload)
        console.log("Document written with ID: ", docRef.id)
      } catch (err) {
        console.log("error deleting data:", err)
      }
    };
    
    ...
    await submit({
        first: "Alan",
        middle: "Mathison",
        last: "Turing",
        born: 1912
    });
    ...
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!