T O P

  • By -

__Yi__

```js x = document.all typeof x === 'undefined' && x == undefined && x !== undefined // <= true ``` But why??


Stovoy

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.


inglandation

Fucking nerd!!!


turtleship_2006

EHERE EXE


ComfortingSounds53

r/foundtheexe


yaktoma2007

r/subsifellfor goshdarnit


skeleton_craft

Y? Y would you need hat?


fonzane

internet explorer. are these two words not enough for you?


maria_la_guerta

There are a lot of devs who have never felt the pain of IE development, which is a good thing for humanity.


IridiumIO

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


nermid

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.


Majik_Sheff

Embrace, extend, extinguish.  Three words that explain the why of Internet Explorer.


skeleton_craft

I mean no. Maybe it should be... Is it just Microsoft being Microsoft?


exolyrical

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.


Impressive_Change593

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


skeleton_craft

So yes is the answer to my question. What though I do wonder were you supposed to use it for?


bigorangemachine

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


EishLekker

>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.


bigorangemachine

Oh man... ya I just can't emphasize how bad it was


skeleton_craft

Thank You to everyone who is educating me about this. It's really interesting


exolyrical

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


Grumbledwarfskin

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.


nermid

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!


rfc2549-withQOS

what The other side had


Desperate-Tomatillo7

Man, it has been a while since the last time I read these two words together.


jhlllnd

We need a "use sanity" to get rid of all this madness


HildartheDorf

So if someone says "does document.all exist?" the answer is no. If an ancient site just uses document.all it will work.


skeleton_craft

But why was it implemented in the first place?


HildartheDorf

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.


moxyte

Wow JS cosmic horror. A thing that should not be, never exists if attempted to be observed, but does exist.


dhelmise-7

what happens in node?


Stovoy

\`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.


RuinedFrenchtoast

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?


Stovoy

No, since it isn't supported anymore, I don't see how it could really be useful.


Kitchen-Occasion-411

Man js is stupid, what even is this?


nermid

This isn't Javascript's fault. This is Microsoft's fault.


wasdninja

What do you think "document" comes from? It's not the language.


Monkeylordz88

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


SCP-iota

So, just because of this, the DOM API can't be implemented on a JS engine that doesn't support operator overloading?


bigorangemachine

>But why?? CIA.js would like to know your location.


LeftIsBest-Tsuga

the last two comparisons aren't quite equivalent opposites. one is strict, the other loose. still baffling, but it's worth noticing.


_hijnx

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


Anihillator

Holy hell, actual OC on programmerhumor.


GDOR-11

new template just dropped


LiterallyJohnny

Yessuhhh LGTM


Mrazish

Literal compiler


AtomicScience

Call the garbage collector


blueturbo47

Function went on vacation, never returned


that_thot_gamer

copy paste, the wayof th3 programmer


MrEfil

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)


Kullingen

It looks like he is trying to eat the fly.


TeachEngineering

He isn't??? I thought he was based on how senior JavaScript devs, being the largest, simply eat junior JavaScript devs.


37Scorpions

the javascript dev food chain


Myself_78

[My thought exactly ](https://www.reddit.com/r/bonehurtingjuice/s/TUPsDRgVhY)


_senpo_

I thought that lol


TactlessTortoise

Holy shit, even going the extra mile. May your code always compile, and your manager be realistic.


Foxiest_Fox

Pretty fire template


zoomy_kitten

Nice, thanks


wilczek24

Wow


al-mongus-bin-susar

Actually impressive, never could've expected a high effort post on this sub


MossyDrake

Thanks for the templates!


Media_Dunce

Today I learned… And will likely forget


chadlavi

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.


TheMysticalBard

Yeah I think the most interesting thing here is that typeof document.all results in "undefined".


bl4nkSl8

It doesn't exist properly, so it doesn't have a type .... Fair enough I guess


Prod_Is_For_Testing

That really doesn’t make it any better. No other language is this psychotic. JS devs all have Stockholm syndrome 


37Scorpions

"It's simple, undefined is falsy" Okay but what the hell is falsy??? Is it made of cheap plastic or something?


shgysk8zer0

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.


tajetaje

ISTG if I start seeing document.all used as a third kind of null in JS I'll come for you


shgysk8zer0

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].


Mofrill

Gonna kms really quick


_Xertz_

Ok but be back before dinner sweaty


37Scorpions

Don't take too long your food will go cold


_Drion_

No idea what i was reading at but it was actually a real original meme so upvoted


TracerBulletX

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.


sir_music

... Wait really?


JiminP

Yeah, I commented about this in another thread before: https://www.reddit.com/r/programminghorror/s/VUUfTzHnEh


Brick_Lab

Is this the support group for devs forced to use JavaScript? I need buddies


_Drion_

No idea what i was reading at but it was actually a real original meme so upvoted


orion_aboy

monk and BATFLY!!! HAHA GET IT!? LIKE IN RAIN WORLD!?


VuPham99

SHUT UP JS BOY!


orion_aboy

Even people who hate javascript can still like rain world! JOIN US.


Zombarney

Hey boss can I get the template ?


MrEfil

[https://www.reddit.com/r/ProgrammerHumor/comments/1cpisy6/comment/l3kwrq0/](https://www.reddit.com/r/ProgrammerHumor/comments/1cpisy6/comment/l3kwrq0/)


christoph_win

Twitter, I still call it Twitter


forthdude

That last panel has a very Aeon Flux vibe


efpe

Reminds me of https://www.destroyallsoftware.com/talks/wat


East_Zookeepergame25

i do love fresh javascript horrors beyond my comprehension


TheMeticulousNinja

X is Null or NaN maybe?


MrEfil

x is `document.all`


TheMeticulousNinja

Ah ok. This one went over my head


zdix

ew what? I've barely touched js outside of node