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

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

Câu trả lời
  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

senior

Giải thích về Hoisting trong Javascript?

middle

3 giai đoạn của event propagation trong Javascript là gì?

middle

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

Bình luận

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