Câu hỏi phỏng vấn Javascript
Câu hỏi

Kết quả đoạn code javascript sau là gì? Hãy giải thích chi tiết?

Câu trả lời

javascript Copy
  const promise1 = Promise.resolve("First");
  const promise2 = Promise.resolve("Second");
  const promise3 = Promise.reject("Third");
  const promise4 = Promise.resolve("Fourth");

  const runPromises = async () => {
    const res1 = await Promise.all([promise1, promise2]);
    const res2 = await Promise.all([promise3, promise4]);
    return [res1, res2];
  };

  runPromises()
    .then((res) => console.log(res))
    .catch((err) => console.log(err));
  • A: [['First', 'Second'], ['Fourth']]
    ...
middle

middle

Gợi ý câu hỏi phỏng vấn

middle

Con trỏ this trong javascript là gì?

middle

Giải thích về phương thức call(), aplly()bind() trong Javascript?

middle

Sự khác biệt giữa await và từ khóa yield trong Javascript là gì?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào