Skip to content
Advertisement

console.log doesn’t wait “await” in async function

I have this code

JavaScript

I want console to wait until onload function ends (when x = true), but this doesn’t happen, console returns false and doesn’t wait

this is the output:

enter image description here

I want an explanation not just the solve

Advertisement

Answer

You need to turn the dataget function to return a promise which will resolve after the onload function executed, so you can await it and return the result.

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