anonymous coward anonymous coward - 1 year ago 72
Javascript Question

Why is `document.all` falsy?

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

For example, this code doesn't do anything:

if (document.all) {

Can someone explain why this is?

Answer Source

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 :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download