Skip to content
DevMeme
When document.all defies every JavaScript check and Gandalf just yells RUN
Frontend Post #69, on Feb 7, 2019 in TG

When document.all defies every JavaScript check and Gandalf just yells RUN

Why is this Frontend meme funny?

Level 1: The Ghost That Says It's Not Home

Imagine knocking on a house's door and a voice answers, "Nobody lives here!" You peek in the window — someone is clearly inside, you can see them moving around. You ask, "Are you nobody?" and they say "No, I'm not nobody!" That's this creature: a thing in the computer that's obviously there, but officially answers "I don't exist" when asked — because long ago, pretending to be absent kept old websites from breaking. The wizard's journey from "stand your ground" to a terrified, blurry "RUN" is every programmer meeting this ghost for the first time: brave, then educated.

Level 2: A Field Guide to the Haunting

  • document.all — an ancient browser API listing every element on the page. Modern code uses document.querySelector instead; this one survives only so 1998-era websites keep working.
  • typeof — an operator that reports a value's type as a string: "number", "string", "object"... It's supposed to be the reliable way to check what something is. The meme shows the one value where it deliberately lies.
  • == vs === — loose equality (==) converts types before comparing and has special-case rules; strict equality (===) compares exactly. Notice in the console: the same pair of values answers differently depending on which you use. This is why style guides default to ===.
  • Falsy — values treated as false in conditions (0, "", null, undefined...). Objects are always truthy — except this single one, the only falsy object in JavaScript.

The junior rite of passage here is learning that "check the type, then act" is sturdier in theory than practice: the platform itself contains exceptions older than your career, kept alive on purpose.

Level 3: Legacy Compat Is the Balrog

The meme's two-panel structure maps the developer's psychological arc with precision. Top panel: calm, resolute Gandalf — "No matter what comes through that gate, you will stand your ground" — over a console showing reassuring facts. document.all returns an HTMLAllCollection of 2784 elements; instanceof Object says true. The world is ordered. Bottom panel: the infamous blurry "RUN" frame, over typeof returning "undefined" for a value that is demonstrably not undefined.

The senior insight is that this isn't a bug, and that's what makes it scarier than a bug. Bugs get fixed. This is policy: the web's prime directive — don't break existing pages — institutionalized into the language spec. Every platform engineer recognizes the pattern, because every long-lived system accrues these deliberate inconsistencies: the API that returns the wrong status code because three large customers depend on it, the flag that inverts behavior because the original sign convention shipped backwards. document.all is merely the canonical, standards-blessed specimen. There's a delicious detail visible in the collection dump itself: among the style, link, and meta elements are entries like #cliqz-adblocker-css-rules and #ghostery-purple-box — the developer's own ad-blocker extensions are part of the 2784 elements being enumerated. Even the screenshot has uninvited dependencies.

The practical moral for working developers: feature-detect with modern patterns, never trust typeof as ontological truth, and treat == null as the deliberate idiom it is (it matches null, undefined — and, by spec exception, exactly one ancient ghost). The gate Gandalf guards is the type system; what comes through it is twenty-five years of backward compatibility, and no, you will not stand your ground.

Level 4: The [[IsHTMLDDA]] Exotic Object

What Gandalf is fleeing has a formal name in the ECMAScript specification: an object with the [[IsHTMLDDA]] internal slot — literally "Is HTML Document.all," a spec mechanism invented for exactly one value in the entire observable universe. The console transcript in the meme is a faithful tour of its sanctioned lies:

document.all                      // HTMLAllCollection(2784) — clearly an object
document.all instanceof Object;   // true — yes, definitely an object
typeof document.all               // "undefined" — wait.
document.all === undefined        // false — it isn't undefined!
document.all == null              // true — but it equals null?!

Under the hood, the spec carves three explicit exceptions for [[IsHTMLDDA]] objects: the typeof operator must return "undefined" instead of "object"; Abstract Equality (==) must treat the object as equal to both null and undefined; and ToBoolean must return false, making it the only falsy object in the language. Strict equality (===) gets no exception — it compares identities honestly — which is why the middle line returns false and completes the paradox triangle.

Why deface the type system this way? Archaeology. document.all was Internet Explorer 4's proprietary DOM API, and late-90s scripts did browser sniffing with if (document.all) { /* IE path */ } else { /* Netscape path */ }. When standards-era browsers implemented document.all for compatibility with old pages, those pages suddenly took the IE code path and broke. The solution was a formally specified lie: make the object exist for code that calls it, but deny existing to code that checks for it. It's the only place where the ECMAScript standard knowingly violates its own type semantics — a Schrödinger value, collapsed differently depending on which operator observes it. Undecidability jokes aside, it's a beautiful demonstration that web compatibility outranks mathematical consistency in the priority order of the universe.

Description

Composite meme with two browser-console screenshots and two frames from a fantasy movie. Top left console shows: “> document.all” followed by an expanded HTMLAllCollection listing, then “> document.all instanceof Object;” and the result “true”. Centered over a blurred movie still of an armored character is white text: “No matter what comes through that gate, you will stand your ground.” Bottom left console snippet continues: “> typeof document.all” returning “"undefined"”; “> document.all === undefined” returning “false”; and “> document.all == null” returning “true”. Bottom right is a motion-blurred wizard shouting with the caption “RUN”. The joke highlights JavaScript’s loose equality, typeof quirks, and the historically odd special-casing of document.all - contrasting confident instructions to hold position with urgent advice to flee once the type system’s absurdity appears

Comments

7
Anonymous ★ Top Pick document.all is JavaScript’s built-in Schrödinger demo: typeof says undefined, instanceof swears Object, and the spec hides it behind IsHTMLDDA - proof TC39 needed a four-letter acronym for “don’t touch this in prod.”
  1. Anonymous ★ Top Pick

    document.all is JavaScript’s built-in Schrödinger demo: typeof says undefined, instanceof swears Object, and the spec hides it behind IsHTMLDDA - proof TC39 needed a four-letter acronym for “don’t touch this in prod.”

  2. Anonymous

    document.all is the quantum particle of web APIs - it exists when observed directly but becomes undefined the moment you try to measure its type, proving that Internet Explorer's legacy code follows Heisenberg's uncertainty principle better than actual quantum mechanics

  3. Anonymous

    document.all is an object whose typeof is 'undefined', isn't === undefined, but == null - the spec literally carved out a lie in the type system so IE4-era code never dies. Legacy compat is the one ring; the standard just learned to carry it

  4. Anonymous

    Ah yes, document.all - the Schrödinger's cat of JavaScript objects. It exists and doesn't exist simultaneously, passes instanceof checks while typeof claims it's undefined, and somehow == null returns true while === undefined returns false. It's the only object in JavaScript that's deliberately falsy, a spec violation so blessed by WHATWG that it got its own [[IsHTMLDDA]] internal slot. This is what happens when backward compatibility with 1990s IE detection code becomes more important than type system sanity. Twenty years later, we're still teaching junior devs why this abomination exists, proving that in web development, technical debt never dies - it just gets enshrined in the spec

  5. Anonymous

    document.all: where typeof says "undefined", == says null, Boolean says true, and the spec says we’re still paying off IE4 interest

  6. Anonymous

    IE's document.all saunters up: Gandalf sniffs typeof() - 'undefined'. Bridge: *yeets into abyss*

  7. Anonymous

    document.all is the [[IsHTMLDDA]] that makes typeof lie, == reenact 1999 IE detection, and every architect's threat model simply says: run

Use J and K for navigation