All current browsers expose a non-standard host objectwith type Undefined.
typeof document.all === 'undefined';
Although the specification allows custom type tags for non-standard exotic objects, it requires those type tags to be different from the predefined ones. The case ofhaving type tag
document.allmust be classified as an exceptional violation of the rules.
console.log("typeof: " + typeof document.all);
console.log("toString: " + document.all);
toString: [object HTMLAllCollection]
Take a look at this one from Html Spec
allattribute must return an
HTMLAllCollectionrooted at the
Documentnode, whose filter matches all elements.
The object returned for
allhas several unusual behaviors:
The user agent must act as if the Abstract Equality Comparison algorithm, when given the object returned for
truewhen compared to the
nullvalues. (Comparisons using the Strict Equality Comparison algorithm, and Abstract Equality comparisons to other values such as strings or objects, are unaffected.)
The third case is yours.
The rationale for this is compatibility with code designed for old browsers, as explained in a note in the specification:
This violation is motivated by a desire for compatibility with two classes of legacy content: one that uses the presence of
document.allas a way to detect legacy user agents, and one that only supports those legacy user agents and uses the
document.allobject without testing for its presence first.
Hope it will make sense for you.