Tricky Outputs

Preview — 3 of 10 questions

What is the output?

javascript
for (var i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 0);
}
A0 1 2
B3 3 3
Cundefined undefined undefined
D0 0 0

What is the output?

javascript
function makeCounter() {
  let count = 0;
  return function () {
    count++;
    return count;
  };
}

const counter = makeCounter();
console.log(counter());
console.log(counter());
console.log(counter());
A0 0 0
B1 1 1
C0 1 2
D1 2 3

What is the output?

javascript
const obj = {
  name: "Alice",
  greet: function () {
    setTimeout(function () {
      console.log(this.name);
    }, 0);
  },
};
obj.greet();
A"Alice"
Bundefined
CReferenceError
Dnull

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.