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
  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...

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

middle

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

junior

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

middle

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

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

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