Recently I investigated a situation in which a programmer inadvertently passed undefined
into addEventListener, thus:
window.addEventListener('load', undefined);
No error was thrown. It's as if JavaScript is willing to invoke undefined
. But what in the world is undefined()
? I have tried all sorts of things, e.g.:
console.log(undefined() === null);
console.log(typeof undefined());
but I never get anything back.
Edit added for clarity: My original question was based on a mistake, as I had not set my Developer tools to log errors to the console. The above two commands (but not the call to addEventListener
) DO throw errors in a browser, as answers and comments below indicate.
It's as if JavaScript is willing to invoke
undefined
.
No, addEventListener
is specified to ignore null
, which JavaScript’s undefined
is converted to. undefined
is never called.
Further proof that JavaScript is not willing to invoke undefined
, in a browser:
> undefined()
Uncaught TypeError: undefined is not a function
at <anonymous>:1:1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With