0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Promise JavaScript

Last updated at Posted at 2024-09-22

Terminology

  • CallStack
  • Task queue
  • Promise

関数実行順番

実行順番について勘違いしていたのでまとめる

  1. orderExecutor 呼ばれてCallStack に入る
  2. orderExecutorがCallStackから出る
  3. thenがTask queueに入る
  4. console.log('2')呼ばれてCallStack に入る
  5. console.log('2')がCallStackから出る
  6. CallStackがEmptyなったのでthenがTask queueからCallStackに入る
  7. thenが実行される
promise.js

function orderExecutor(resolve, reject) {
    console.log('1'); // 1
    resolve('3');
}
let orderPizza = new Promise(orderExecutor);
orderPizza.then(function (value) {
    console.log(value); // 3
});
console.log('2'); // 2

// 1, 2, 3

Reference

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?