We know that we have to preserve the value of this
in callbacks in order to execute them with appropriate context. For example:
someArr.forEach(function(el) { console.log(this); });
Here this
will be referring to window or undefined when we use use strict
.
But when we are adding an event for example:
someBtn.addEventListener('click', function() {
console.log(this);
});
Here this
refers to the button which is clicked. How come in this callback we dont have to bind any this while in former case we have to bind it explicitly.
I can be wrong so please clarify my doubt.