What does HackerNews think of wtfjs?

🤪 A list of funny and tricky JavaScript examples

Language: JavaScript

#12 in JavaScript
#1 in JavaScript
From 2010:

https://news.ycombinator.com/item?id=1121932

https://github.com/denysdovhan/wtfjs

My my, how HN sensibilities change over time. Hacker news, the place where the language police now rains supreme eh?

I've tried it on a few of the wtfjs examples, and it explains the snippets surprisingly well, sometimes even better than the original explanations!

https://whatdoesthiscodedo.com/g/cfa4c2c

https://github.com/denysdovhan/wtfjs

> Any non-trivial code work is done in JavaScript, anyway.

JavaScript is strongly-typed though, it just lacks a way to declare types. One can easily restrict types in script code (using `typeof` for primitives and `instanceof` for object prototypes).

People refer to it as "weakly-typed" because most (but not all) of the built-in types have implicit conversions to other types; and many of which are non-obvious: https://github.com/denysdovhan/wtfjs

No, I'm talking about js as a whole. Standard library is crap, inconsistent, even the most basic of naming conventions are not followed anywhere. The fact that the standard library jumps between camel case, pascal case, snake case and unicase at random is a perfect example. The list of absurdities is beyond ridiculous[1].

[1] https://github.com/denysdovhan/wtfjs

Yeah, JavaScript has problems but come on, just the fact that it has closures and first-class functions (and did a lot to popularize both, for that matter) makes it pretty cool in my book. It's a fun and powerful language.

The author also trots out the standard go-to argument of JavaScript haters. He writes that JavaScript "has deeply ingrained quirks and bugs which can never be fixed without breaking the millions of scripts that have made peace with the existence of those bugs and depend upon the well-known workaround" and he links to https://github.com/denysdovhan/wtfjs, a typical list of JavaScript's well-known type-casting quirks, etc.

Pretty much all languages have little quirks. Actual JavaScript programmers usually learn how to avoid JavaScript's quirks pretty quickly and easily. In my experience, people who fixate on JavaScript's quirks generally do not understand the language very well. If they did, they could criticize more substantial things about JavaScript than just things like "[] == ![]; // -> true".

If you like this kind of thing, you might enjoy "WTF, JS?"

https://github.com/denysdovhan/wtfjs

Or it's slightly older brother "WTF, Python?"

https://github.com/satwikkansal/wtfpython

Agreed. Even in Linux, complete documentation for userland tools is usually a given.

Not so with webdev. That said, the source code is there for all of us to read. I'm a frontend developer and spend more time looking at source code when I need to figure out an issue than digging through Medium posts. Particularly when something is behaving in an unexpected manner.

I'd urge everyone who hates webdev to try this approach the next time they struggle with an issue. JavaScript, for all its sins, is fairly easy to read. And once you've understood the ~30 most common gotchas in JS, reading the source is highly beneficial (and here's a good intro to those gotchas, including an accompanying video: https://github.com/denysdovhan/wtfjs)

Or better yet, work in one of the statically-typed compile-to-JS languages such as Typescript, ReasonML, Elm, ScalaJS, or Purescript and worry about those gotchas much less (and only when wrapping external libraries).

Maybe https://github.com/denysdovhan/wtfjs counts as leaky abstractions.

It's definitely something that's difficult with building a language. Abstracting and generalizing your language parser can lead to amigious behavior.

Arch | New York, NY | https://archlabs.com | ONSITE | VISA | $100K - 175K w/ significant equity

Arch is an early stage NYC-based, Fintech startup in the alternative investment industry with paying customers. Our engineering team is a couple of MIT alums who were previously early engineers at successful startups that have since IPO'd. We are being advised by a founder/investor with two successful exits (who was also the eighth user of Dropbox).

We're looking to grow our three person team. Contact us if:

- Your favorite fruit in JavaScript is ('b' + 'a' + + 'a' + 'a') (Arch does not discriminate against apple or orange lovers)

- You think https://github.com/denysdovhan/wtfjs is interesting, but looks nothing like your code

Fullstack - https://angel.co/arch-4/jobs/375451-senior-full-stack-engine...

Frontend - https://angel.co/arch-4/jobs/375452-senior-front-end-enginee...

Apply above or reach out to [email protected]

Javascript and numerics. That is my takedown of javascript. If you don't know why its bad for numerics[1] or just generally weird [2][3] ...

No, JS shouldn't be used as a systems language IMO. It gives you enough rope to shoot yourself in the foot (multiple mixed metaphors for a reason).

[1] https://charlieharvey.org.uk/page/javascript_the_weird_parts

[2] https://hackernoon.com/js-wtf-with-math-79da9a941ec1

[3] https://github.com/denysdovhan/wtfjs

Know the details around bind, 'this', dot operator, 'new', call/apply, 'in', variable hoisting, the actual data types JS provides out of the box (Longs aren't one of them) and some assortment of new features/proposed features like classes, and you'll be ahead of lots of seniors. Personally I'd appreciate a good showing in knowledge of the standard library, where its gaps/gotchas are, levels of browser support... (e.g. even IE11 supports sets -- we can use actual built-in set data structures! -- just not the full API. But it has the minimum.)

I agree with others though that you probably won't get the trivia treatment, I wouldn't give one and I don't see them being done by coworkers... But it doesn't hurt to be prepared. So long as you don't present yourself as a "Master" I would think the knives would be less likely to come out. Things like this github has https://github.com/denysdovhan/wtfjs are on the mean spectrum to use against some so-called master, the meanest might probably be demanding they do something with representations like in http://patriciopalladino.com/blog/2012/08/09/non-alphanumeri...

That is a fine JS editor you have got up there. we should create links for most of those w t f s here https://github.com/denysdovhan/wtfjs