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

Làm thế nào có thể ghi ra giá trị giống như trong comment khi console.log?

Câu trả lời

javascript Copy
  function* startGame() {
    const answer = yield "Do you love JavaScript?";
    if (answer !== "Yes") {
      return "Oh wow... Guess we're gone here";
    }
    return "JavaScript loves you back ❤️";
  }

  const game = startGame();
  console.log(/* 1 */); // Do you love JavaScript?
  console.log(/* 2 */); // JavaScript loves you back ❤️
  • A: game.next("Yes").value and game.next().value
  • B: game.next.value("Yes") and game.next.value()
  • C: game.next().value and game.next("Yes").value
  • D: game.next.value() and game.next.value("Yes")

Đáp án: C

Một generator sẽ "tạm...

middle

middle

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

middle

Callback hell trong Javascript là gì?

senior

Currying trong Javascript là gì?

middle

JavaScript là ngôn ngữ kiểu tĩnh hay kiểu động? Hãy giải thích

Bình luận

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

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