system
Given the following post, respond as if you're commenting on Reddit:
human
Why aren't linked lists and other data structures built-in to Javascript?

I've googled as much as I can to find the answer, but every result I come across is just "*Datastructures Basics! How to make a singly linked list!*", but my question is more about the *why*. If linked lists, stacks, queues, trees, binary trees, etc. are used so often and are even an expected skill to demonstrate in tech interviews, why aren't they a standardized data structure in languages like Javascript?

From what I've read, *some* of these structures are available in other languages (JavaScript is the only language I'm very comfortable with, so please correct me if I'm wrong). Is it merely a preference thing from the core devs? Does it include an unnecessary overhead? Are these data structures just not used enough to matter?

Thanks!
gpt
There’s a lot to unpack in the question so let’s start at the beginning:

Why doesn’t JavaScript have a bunch of data structures built in?

I think there are two factors here: first, JavaScript wasn’t originally built with its current uses in mind. The goal was to give people a way to add some interactivity to otherwise static documents. JavaScript was around for a long time before websites started to move away from being documents with some interactive elements and toward being full fledged applications. Even when that transition was first happening, there was an attitude that the browser should implement all of the interesting things, and JavaScript existed merely to automate using functionality the browser supported. Internally the browsers use plenty of sophisticated data structures, but for a long time nobody really thought about JavaScript as a language for building sophisticated software.

Eventually people did start to see JavaScript as a language for writing real programs, but by that point the momentum was behind using packages and frameworks. JavaScript itself never got much of a rich general purpose standard library because other projects stepped in by the time anyone realized it could have used one. Now days it’s just cultural- if you need a data structure just add a dependency to your project, for better or worse that’s the JavaScript way.

So that explains JS, but why don’t other languages implement these data structures? Often they do, to some degree or another.

JavaScript is at one extreme as a language with basically nothing built in, but all languages need to decide what to include and what not to include by default. There’s no right answer only trade offs, but the major focus is trying to write things that are generally useful to a lot of users. It’s not a good use of time and resources to invest in building fancy data structures that nobody will use.

That brings us to your last question - does nobody use these?

Fancy data structures are used less often than you might think. Most of the time you can get by with lists, arrays, and dictionaries. When you do need a fancy data structure, it’s often because you have a very specific use case in mind, and in those cases your often better implementing it yourself so that you can tune it to your specific needs. Even if the language provided a general purpose library, it wouldn’t be tuned for your exact needs so you’d still write your own.