Why AJAX is asynchronous
Code after fetch runs before the reply comes back. Use then or await to wait.
AJAX · Why AJAX is asynchronousBeginner
console.log('1. before');
fetch('/api/items').then(function () {
console.log('3. reply arrived');
});
console.log('2. after (runs before the reply!)');asynccallbackorderpromise