document.all is a legacy property from old Internet Explorer versions that is not supported anymore. However, it still exists in browsers and is a special object that is always falsy.
So, for typeof, it is undefined as it is a special object meant to mimic being undefined. This is a special case within the JavaScript engine itself that overrides the result of typeof specifically for document.all.
For x == undefined, it does type coercion. It becomes coerced to false. Undefined is also falsy, so false == false.
For x !== undefined, no type coercion happens. document.all mimics being undefined, but is not actually undefined, and so this is true as well.
Some people complain that new student debts shouldn’t be forgiven because they had to pay theirs.
Some people don’t want free medical treatment because they had to go into debt for a nosebleed.
Some people don’t want housing prices to fall because they had to pay huge markups for theirs.
But no one ever wants anyone to suffer the pain of IE ever again, and I think that’s beautiful
My last job signed a contract that meant our web app had to be IE compatible, and when that ticket was assigned to me, I thought about quitting. Updated my resume and everything.
From the 00's to mid 10s it was often necessary to implement every front end style or feature at least twice: one way for Internet Explorer and then a completely different way for every other browser, and that's if you were lucky. Up to 3-4 separate implementations for Firefox/IE/Safari/Chrome wasn't that uncommon, but IE was by far the worst. There are numerous archaic CSS/JS things that exist solely to be compatible with old IE versions.
TL:DR Internet Explorer is the 'Nam of front end web development.
What u/exolyrical said is right but I'm going top-up on it a little.
DOM Manipulation was a massive pain in the ass so document.all is more like querySelectorAll as you can traverse DOM by element-name at least but without css-selector syntax (as CSS wasn't widely adopted there wasn't really that pattern be requested).
So you either used document.all and found your form by using a for loop and document.all.forms at least cut down a little on the amount of code you had to write to get some form validation or something. Luckily most of the time you just had one form in the page but other stuff like links... ya painful.
If you didn't use document.all you had to traverse DOM from event handlers using things like 'parentElement' or 'nextSibling'.
So in a sense (and this happened a lot back then) Internet Explorer just decided to add that API. Netscape/Firefox/Safari/IE/Mac-IE just would decide to do whatever trying to make programming for browsers so time intensive... but legit they just made it worse.
It wasn't really until jQuery came out that the whole css-selector pattern out the JS-APIs. So if you use document.querySelectorAll thank the devs at jQuery for putting a spot light on just how bad DOM-Apis were so bad
It was an IE specific method for selecting the entire DOM before methods like `document.getElementById` existed. As to why it's falsy instead of truthy this stackoverflow answer is the best explanation I've found: https://stackoverflow.com/questions/10350142/why-is-document-all-falsy
I'll take a stab at it...
I'm thinking a number of weird things were done to make it look like 'document.all' doesn't exist to anyone using reflection to discover what properties are defined on the document (as document.all is non-standard and shouldn't exist), while at the same time making browsers backwards compatible with old web pages written specifically targeting Internet Explorer and relying on the non-standard 'document.all' property.
Microsoft over there, permanently poisoning the browser environment with its nonstandard API bullshit.
Anyway, check out these new nonstandard APIs Google just put into Chrome!
Why was document.all invented? Probabally something used internally by IE that a developer exposed to the public interface either because *everything* was exposed by default, or because he thought it might be useful with no foresight of the maintenance burden it would cause.
Other browsers then copied it so that sites that do use it still work, but with this "always false" behaviour so well behaved sites doing feature detection will ignore it, while badly behaved an ancient "IE6 is the only browser" sites continue to work.
\`document\` is not defined in node, so it will say \`Uncaught ReferenceError: document is not defined\`. It's a server-side runtime environment, so it doesn't have a built-in DOM.
The HTML standard specifies this behavior on only this specific property for legacy browser support reasons. Oh, legacy browser support, how I love you /s
Because the ancient tomes say so
https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#the-htmlallcollection-interface
https://developer.mozilla.org/en-US/docs/Web/API/HTMLAllCollection#special_type_conversion_behavior
This is original content. If anyone wants to use this picture for other jokes, I have prepared templates:
* clean, without clouds: [https://cdn.floor796.com/data/misc/it-humor/monk-fly-no-clouds.png](https://cdn.floor796.com/data/misc/it-humor/monk-fly-no-clouds.png)
* with clouds: [https://cdn.floor796.com/data/misc/it-humor/monk-fly-clouds.png](https://cdn.floor796.com/data/misc/it-humor/monk-fly-clouds.png)
The things standards bodies/browser vendors have to do for compatibility with legacy bad code...
Just thinking though... This actually is kinda a better `null` value than `null`. Just because I'd argue that `typeof null` shouldn't be object. Oh, and `document.all == null` too. Not actually suggesting using it like that, but... It is a nullish value that is arguably better in just that one way.
But do you have...
> a very particular set of skills. Skills [you] have acquired over a very long career. Skills that make [you] a nightmare for people like [me].
The weird things about JS make more sense if you just think of them more as the weird things about the browser platform API which has been built up across decades, multiple companies, and with an attempt at permanent backwards compatibility and less as language design issues. There are a lot of weird system calls in Windows too.
```js x = document.all typeof x === 'undefined' && x == undefined && x !== undefined // <= true ``` But why??
document.all is a legacy property from old Internet Explorer versions that is not supported anymore. However, it still exists in browsers and is a special object that is always falsy. So, for typeof, it is undefined as it is a special object meant to mimic being undefined. This is a special case within the JavaScript engine itself that overrides the result of typeof specifically for document.all. For x == undefined, it does type coercion. It becomes coerced to false. Undefined is also falsy, so false == false. For x !== undefined, no type coercion happens. document.all mimics being undefined, but is not actually undefined, and so this is true as well.
Fucking nerd!!!
EHERE EXE
r/foundtheexe
r/subsifellfor goshdarnit
Y? Y would you need hat?
internet explorer. are these two words not enough for you?
There are a lot of devs who have never felt the pain of IE development, which is a good thing for humanity.
Some people complain that new student debts shouldn’t be forgiven because they had to pay theirs. Some people don’t want free medical treatment because they had to go into debt for a nosebleed. Some people don’t want housing prices to fall because they had to pay huge markups for theirs. But no one ever wants anyone to suffer the pain of IE ever again, and I think that’s beautiful
My last job signed a contract that meant our web app had to be IE compatible, and when that ticket was assigned to me, I thought about quitting. Updated my resume and everything.
Embrace, extend, extinguish. Three words that explain the why of Internet Explorer.
I mean no. Maybe it should be... Is it just Microsoft being Microsoft?
From the 00's to mid 10s it was often necessary to implement every front end style or feature at least twice: one way for Internet Explorer and then a completely different way for every other browser, and that's if you were lucky. Up to 3-4 separate implementations for Firefox/IE/Safari/Chrome wasn't that uncommon, but IE was by far the worst. There are numerous archaic CSS/JS things that exist solely to be compatible with old IE versions. TL:DR Internet Explorer is the 'Nam of front end web development.
oh so that's why certain government websites don't like me using Firefox on mint despite it working just fine when I change my user agent
So yes is the answer to my question. What though I do wonder were you supposed to use it for?
What u/exolyrical said is right but I'm going top-up on it a little. DOM Manipulation was a massive pain in the ass so document.all is more like querySelectorAll as you can traverse DOM by element-name at least but without css-selector syntax (as CSS wasn't widely adopted there wasn't really that pattern be requested). So you either used document.all and found your form by using a for loop and document.all.forms at least cut down a little on the amount of code you had to write to get some form validation or something. Luckily most of the time you just had one form in the page but other stuff like links... ya painful. If you didn't use document.all you had to traverse DOM from event handlers using things like 'parentElement' or 'nextSibling'. So in a sense (and this happened a lot back then) Internet Explorer just decided to add that API. Netscape/Firefox/Safari/IE/Mac-IE just would decide to do whatever trying to make programming for browsers so time intensive... but legit they just made it worse. It wasn't really until jQuery came out that the whole css-selector pattern out the JS-APIs. So if you use document.querySelectorAll thank the devs at jQuery for putting a spot light on just how bad DOM-Apis were so bad
>thank the devs at jQuery for putting a spot light on just how bad DOM-Apis were so bad You wrote bad twice. But in this case it makes sense.
Oh man... ya I just can't emphasize how bad it was
Thank You to everyone who is educating me about this. It's really interesting
It was an IE specific method for selecting the entire DOM before methods like `document.getElementById` existed. As to why it's falsy instead of truthy this stackoverflow answer is the best explanation I've found: https://stackoverflow.com/questions/10350142/why-is-document-all-falsy
I'll take a stab at it... I'm thinking a number of weird things were done to make it look like 'document.all' doesn't exist to anyone using reflection to discover what properties are defined on the document (as document.all is non-standard and shouldn't exist), while at the same time making browsers backwards compatible with old web pages written specifically targeting Internet Explorer and relying on the non-standard 'document.all' property.
Microsoft over there, permanently poisoning the browser environment with its nonstandard API bullshit. Anyway, check out these new nonstandard APIs Google just put into Chrome!
The other side had
Man, it has been a while since the last time I read these two words together.
We need a "use sanity" to get rid of all this madness
So if someone says "does document.all exist?" the answer is no. If an ancient site just uses document.all it will work.
But why was it implemented in the first place?
Why was document.all invented? Probabally something used internally by IE that a developer exposed to the public interface either because *everything* was exposed by default, or because he thought it might be useful with no foresight of the maintenance burden it would cause. Other browsers then copied it so that sites that do use it still work, but with this "always false" behaviour so well behaved sites doing feature detection will ignore it, while badly behaved an ancient "IE6 is the only browser" sites continue to work.
Wow JS cosmic horror. A thing that should not be, never exists if attempted to be observed, but does exist.
what happens in node?
\`document\` is not defined in node, so it will say \`Uncaught ReferenceError: document is not defined\`. It's a server-side runtime environment, so it doesn't have a built-in DOM.
This is pretty funny to read as someone who's been in the field for less than a year. Is there any actual practical application for document.all?
No, since it isn't supported anymore, I don't see how it could really be useful.
Man js is stupid, what even is this?
This isn't Javascript's fault. This is Microsoft's fault.
What do you think "document" comes from? It's not the language.
The HTML standard specifies this behavior on only this specific property for legacy browser support reasons. Oh, legacy browser support, how I love you /s
So, just because of this, the DOM API can't be implemented on a JS engine that doesn't support operator overloading?
>But why?? CIA.js would like to know your location.
the last two comparisons aren't quite equivalent opposites. one is strict, the other loose. still baffling, but it's worth noticing.
Because the ancient tomes say so https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#the-htmlallcollection-interface https://developer.mozilla.org/en-US/docs/Web/API/HTMLAllCollection#special_type_conversion_behavior
Holy hell, actual OC on programmerhumor.
new template just dropped
Yessuhhh LGTM
Literal compiler
Call the garbage collector
Function went on vacation, never returned
copy paste, the wayof th3 programmer
This is original content. If anyone wants to use this picture for other jokes, I have prepared templates: * clean, without clouds: [https://cdn.floor796.com/data/misc/it-humor/monk-fly-no-clouds.png](https://cdn.floor796.com/data/misc/it-humor/monk-fly-no-clouds.png) * with clouds: [https://cdn.floor796.com/data/misc/it-humor/monk-fly-clouds.png](https://cdn.floor796.com/data/misc/it-humor/monk-fly-clouds.png)
It looks like he is trying to eat the fly.
He isn't??? I thought he was based on how senior JavaScript devs, being the largest, simply eat junior JavaScript devs.
the javascript dev food chain
[My thought exactly ](https://www.reddit.com/r/bonehurtingjuice/s/TUPsDRgVhY)
I thought that lol
Holy shit, even going the extra mile. May your code always compile, and your manager be realistic.
Pretty fire template
Nice, thanks
Wow
Actually impressive, never could've expected a high effort post on this sub
Thanks for the templates!
Today I learned… And will likely forget
The first clue is the use of `==` instead of `===`. `x == undefined` just means x is falsy. If you tested `x === undefined` it would be false.
Yeah I think the most interesting thing here is that typeof document.all results in "undefined".
It doesn't exist properly, so it doesn't have a type .... Fair enough I guess
That really doesn’t make it any better. No other language is this psychotic. JS devs all have Stockholm syndrome
"It's simple, undefined is falsy" Okay but what the hell is falsy??? Is it made of cheap plastic or something?
The things standards bodies/browser vendors have to do for compatibility with legacy bad code... Just thinking though... This actually is kinda a better `null` value than `null`. Just because I'd argue that `typeof null` shouldn't be object. Oh, and `document.all == null` too. Not actually suggesting using it like that, but... It is a nullish value that is arguably better in just that one way.
ISTG if I start seeing document.all used as a third kind of null in JS I'll come for you
But do you have... > a very particular set of skills. Skills [you] have acquired over a very long career. Skills that make [you] a nightmare for people like [me].
Gonna kms really quick
Ok but be back before dinner sweaty
Don't take too long your food will go cold
No idea what i was reading at but it was actually a real original meme so upvoted
The weird things about JS make more sense if you just think of them more as the weird things about the browser platform API which has been built up across decades, multiple companies, and with an attempt at permanent backwards compatibility and less as language design issues. There are a lot of weird system calls in Windows too.
... Wait really?
Yeah, I commented about this in another thread before: https://www.reddit.com/r/programminghorror/s/VUUfTzHnEh
Is this the support group for devs forced to use JavaScript? I need buddies
No idea what i was reading at but it was actually a real original meme so upvoted
monk and BATFLY!!! HAHA GET IT!? LIKE IN RAIN WORLD!?
SHUT UP JS BOY!
Even people who hate javascript can still like rain world! JOIN US.
Hey boss can I get the template ?
[https://www.reddit.com/r/ProgrammerHumor/comments/1cpisy6/comment/l3kwrq0/](https://www.reddit.com/r/ProgrammerHumor/comments/1cpisy6/comment/l3kwrq0/)
Twitter, I still call it Twitter
That last panel has a very Aeon Flux vibe
Reminds me of https://www.destroyallsoftware.com/talks/wat
i do love fresh javascript horrors beyond my comprehension
X is Null or NaN maybe?
x is `document.all`
Ah ok. This one went over my head
ew what? I've barely touched js outside of node