Cannot determine type of undefined()

Viewed 148

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.

4 Answers
Related