Amar
Amar

Reputation: 145

keyboard EventListener in javascript

can anyone explain me how the argument e is captured and passed as a function callback which displays the keyboardEvent Object in console. Same this can be acheived by using

() => console.log(event);

so why do we do like this

 (e) => console.log(e);
document.addEventListener("keydown", e => {
console.log("key Pressed");
console.log(e);
});

Upvotes: 0

Views: 2072

Answers (1)

Bekim Bacaj
Bekim Bacaj

Reputation: 5965

Event object exists in Spyglass based browsers but doesn't exist in Mosaic based browsers as a scriptable object, or at least as an accessible object.

For this reason Mosaic (which was killed by The Project "Mosaic Killa"), from where we now have Mozilla for short, which in that process developed Netscape Navigator, had to arbitrarily pass the event object as a value of a function argument.

So, in order to be compatible with both worlds, the arbitrary event assignment to the first provided function argument has become mandatory for both.

Although you can still call for the event object in the Spyglass line of browsers, if that's your exclusive target clientele on some intranet app.

Upvotes: 1

Related Questions