Question 1 / 1
A developer writes the following object:
const colorPicker = {
selectedColor: null,
pickColor: function(color) {
setTimeout(function() {
this.selectedColor = color
console.log('Selected:', this.selectedColor)
}, 100)
}
}
colorPicker.pickColor('red')
After 100ms, the console logs 'Selected: undefined'. The developer replaces the setTimeout callback with an arrow function:
setTimeout(() => {
this.selectedColor = color
console.log('Selected:', this.selectedColor)
}, 100)
What does the console log now, and why?