Javascript questions
Hey, i have a few questions about javascript:
1) Why do people not recommend
2) Given the example in the codepen, the code increments a counter when a button is clicked. Why is it that inside of the event listener, i have to wrap calling
Thank you in advance.
1) Why do people not recommend
onclick but rather adding an event listener? What are the differences?2) Given the example in the codepen, the code increments a counter when a button is clicked. Why is it that inside of the event listener, i have to wrap calling
incrementCount() in an arrow function, like so: incrementButton.addEventListener("click", () => incrementCount()), rather than incrementButton.addEventListener("click", incrementCount()) for it to work? If i don't the button doesn't do anything and the count variable is automatically upped to 1 upon page load? https://codepen.io/deerCabin/pen/mdNVBGEThank you in advance.

