Question 17
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const timer = {
seconds: 10,
start() {
function inner() { return this === timer; }
const arrow = () => this === timer;
return [inner(), arrow()];
},
};
console.log(timer.start());
- A [ true, true ]
- B [ false, false ]
- C [ false, true ] Correct
- D [ true, false ]
Correct Answer: Option C
inner() is a plain call, so it gets its own this (the global object here). The arrow function has no this of its own and uses start's this, which is timer.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!