I'm working on a very simple game using vanilla JavaScript and the behavior I'm seeing right now goes against everything I've learned about with functions. I don't understand why getInput
can be called without the usual parenthesis that you'd use when calling functions. In fact, when I add parenthesis like this: document.addEventListener("keydown", getInput());
, it doesn't work at all.
So then, how am I able to receive and print the event key without it having been passed as a parameter?
document.addEventListener("keydown", getInput);
function getInput() {
console.log(event.key);
}