There is this tweet on Twitter:
In JavaScript, all objects are truthy (as per the spec). In the DOM, there’s one exception to this rule. What is it? #jsquiz #fronttrends
Does anyone know the answer?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Disclaimer: I’m the guy who tweeted that 🙂 It was a question I would ask and answer in my Front-Trends talk. I wrote that tweet 5 minutes before going on stage.
Because of the 140-character limit on Twitter, the question is slightly ambiguous. The real question I was asking is the following.
The ECMAScript spec defines
ToBoolean()as follows:As you can see, all non-primitive objects (i.e. all objects that aren’t a boolean, a number, a string,
undefined, ornull) are truthy as per the spec. However, in the DOM, there is one exception to this — a DOM object that is falsy. Do you know which one that is?The answer is
document.all. The HTML spec says:So,
document.allis the only official exception to this ECMAScript rule. (In Opera,document.attachEventetc. are falsy too, but that’s not specced anywhere.)