Skip to content
Advertisement

Why does this function call throws “await is only valid in async function” Syntax Error even though the function is async?

There is a loadJson function that returns the Json of a firebase link

JavaScript

I am trying to assign the value of loadJson() to this variable and use it in a promise.

JavaScript

But why does this code throws the following error?

JavaScript

Advertisement

Answer

your problem is your await here:

JavaScript

if you want the promise call the function without await:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement