Output: setTimeout inside an object method, with a regular callback vs an arrow callback
MediumP1Output
What does this code print?
1const timer = {2 label: 'T',3 regular() {4 setTimeout(function () {5 console.log(this.label);6 }, 0);7 },8 arrow() {9 setTimeout(() => console.log(this.label), 0);10 },11};12timer.regular();13timer.arrow();
Saved automatically
One line per console.log. Arrays as [1, 2, 3], objects as { a: 1 }, an uncaught error as Uncaught TypeError: message (Chrome and Node wording).
Hints
Saved automatically