I've been struggling with the idea of when to receive/pass parameters to JavaScript functions and reading this article on onchange event handlers at MDN helped me crystallize my question. Here's the code from the article:
<input type="text" placeholder="Type something here, then click outside of the field." size="50">
<p id="log"></p>
let input = document.querySelector('input');
let log = document.getElementById('log');
input.onchange = handleChange; //<<< Question on this <<<<<<
function handleChange(e) {
log.textContent = `The field's value is
${e.target.value.length} character(s) long.`;
}
I see that input has an onchange Event handler that provides data to the handleChange() function. It even states that in the docs:
The function receives an Event object as its sole argument.
Yet, I'm struggling to understand how handleChange() is receiving the Event object when it doesn't have parentheses accepting any argument?
input.onchange = handleChange; // Where's the parentheses?
Is the Event object global and that's how handleChange() is manipulating it? If that were the case, couldn't you omit the e argument when defining the function?