So I have been searching around, but was unable to find any mentions of this.
If I want to add an "EventListener" to an element, what would be the "correct" way?
const myHtmlElement = document.getElementById("my-id");
myHtmlElement.addEventListener("change", function(e){ do stuff });
Or should i use let for this instead? Since I’m "adding" an eventlistener?
Or would it more correct to simple do
document.getElementById("my-id").addEventListener("change", function(e){ do stuff });
>Solution :
Use const since you are not doing reassignment of variable.
Const does not mean the value it holds is immutable, it means that the variable identifier cannot be reassigned.
First approach has better readability so go with that definitely.