anonymous coward anonymous coward - 10 days ago 3
Javascript Question

Why is `document.all` falsy?

document.all
is a non-primitive object in the DOM that is falsy.

For example, this code doesn't do anything:

if (document.all) {
alert("hello");
}


Can someone explain why this is?

Answer

document.all is available only on Internet Explorer, webkit and Opera.

On every other browser all is an undefined property of document object (and undefined is considered as a false value)

As historical note: many (really many) years ago document.all was used to tell Internet Explorer from Netscape Navigator so if you meet a script that is checking if (document.all) ... I strongly suggest to find a better script :)

Comments