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

senior

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

junior

Array trong Javascript là gì?

senior

Prototype 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