Why can't fetch data be assigned to a variable?

  • 0
    console.log on line 17 will print an empty array to the console:

    However, when you call console.log (users), but already in the browser debugger, the desired array will be sent to the console:

    JavaScript Anonymous, Dec 25, 2019

  • 1 Answers
  • 0
    Because they haven't been received yet. What is inside then will be executed sometime later, and console.log (users) will be executed immediately after the call (but not the end of the request) sendRequest .

    Read about asynchrony.

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!