Event Object Access In JavaScript: A Surprising Truth
Clicking a button in JavaScript doesn't always work as expected due to `event` being read-only on the `window` object, but it's deprecated and should be accessed via the first parameter of event handlers instead.
Suppose you have the following HTML and JavaScript:
<button id="btn">Click me</button>
let myBtn = document.querySelector("#btn");
myBtn.addEventListener("click", () => {
console.log(event);
});
What do you think clicking on the button will happen?
If you think it will not work, saying event is not defined or something like this, you will surprisedly get the right Event object for that event, unless your browser has stopped caring about it.
What actually happens is that event is a read-only property of window and outside of event handle...