this post was submitted on 05 Aug 2023
8 points (100.0% liked)
JavaScript
1972 readers
3 users here now
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Your variable myVar doesn't get defined until fetch receives the results, but fetch is an asychronous function, so console.log runs before myVar is defined.
If you want to wait for the results of an asynchronous function before proceeding with execution, you need to use the await keyword: