Câu hỏi

Kết quả đoạn code sau là gì?

  const myPromise = () => Promise.resolve("I have resolved!");
  function firstFunction() {
  myPromise().then((res) => console.log(res));
  console.log("second");
  }
  async function secondFunction() {
  console.log(await myPromise());
  console.log("second");
  }
  firstFunction();
  secondFunction();
  • A: I have resolved!, secondI have resolved!, second
  • B: second, I have resolved!second, I have resolved!
  • C: I have resolved!, secondsecond, I have resolved!
  • D: second, I have resolved!I have resolved!, second
junior
Ẩn câu trả lời detail

Đáp án: D

Có thể tưởng tượng đơn giản cách promise thực thi như sau: _bây giờ tôi sẽ để tạm nó sang một bên vì nó tính toán mất thời gian. Chỉ khi nào nó được hoàn thành (resolved) hay bị hủy bỏ (rejecte...

Bạn cần đăng nhập để xem

Gợi ý câu hỏi khác

Sự khác biệt của biến dùng `var`, `let` và `const`

Xem câu trả lời detail

Sử dụng **Promise** trong JavaScript như thế nào?

Xem câu trả lời detail

Đệ quy là gì?

Xem câu trả lời detail

Kết quả đoạn code sau là gì? ```javascript function getAge() { "use strict"; age = 21; console.log(age); } getAge(); ``` - A: `21` - B: `undefined` - C: `ReferenceError` - D: `TypeError`

Xem câu trả lời detail

Kết quả đoạn code sau là gì? ```javascript function checkAge(data) { if (data === { age: 18 }) { console.log("You are an adult!"); } else if (data == { age: 18 }) { console.log("You are still an adult."); } else { console.log(`Hmm.. You don't have an age I guess`); } } checkAge({ age: 18 }); ``` - A: `You are an adult!` - B: `You are still an adult.` - C: `Hmm.. You don't have an age I guess`

Xem câu trả lời detail