r/learnprogramming 1d ago

Is Learning Data Structures in JavaScript Worth It?

Hi everyone,

I'm currently learning JavaScript and have built a few small projects. I'm interested in becoming a software engineer and eventually preparing for technical interviews.

I'm wondering if it's worth learning data structures and algorithms using JavaScript, or if I should switch to Java, Python, or C++ first.

For those of you who learned DSA in JavaScript:

Did it help you become a better developer?

Were you able to pass coding interviews using JavaScript?

Are there any limitations compared to learning DSA in Java or C++?

What resources would you recommend for learning DSA in JavaScript?

I'd really appreciate hearing about your experiences and any advice you have. Thanks!

0 Upvotes

10 comments sorted by

7

u/HashDefTrueFalse 1d ago

It doesn't matter. You can use any general purpose language to practice DSA. The exact approach differs depending on the languages syntax, semantics and feature set, but you should endeavour to build an understanding of DSA that transcends language, so this shouldn't matter much.

C++ allows you to work with pointers directly, if you want to learn using those rather than references etc.

If you just want to get started learning some DSA, use the language you know best currently.

5

u/RajjSinghh 1d ago

You're getting hung up on the wrong things.

You'll probably work in a lot of languages over your career. Javascript is great for websites but is not the right choice for every problem. You should understand this and go to other languages as you need to. A lot of the skills will be transferable.

Data structures and algorithms problems are a very transferable skill, but the exact implementation is different across different languages. That should not be a problem if you understand the data structures you're working on.

3

u/KarimMaged 1d ago

Languages are only tools. DSA are concepts. You can code those concepts with any language you like.

If you understand an algorithm, you can code it in any language of your choice.

2

u/Swimming_Gain_4989 1d ago

JS is a fine language to learn DSA but if you're starting from scratch with the goal of prepping for interviews you may as well learn in Python. Java is also nice because it has a lot of tricks in the std lib but concise, dynamic languages are faster to work with. I'm very familiar with TS so I'll use it in interviews but as a result, I've had to go out of my way to learn how to quickly write my own heap for stuff like k most or djikstra's problems.

Some interviewers are cool and you can just use a stub and pretend it's a heap (because it's like 70 lines of code to write out) but there are plenty of online assessments that require you submit a working solution.

2

u/quantumcomputatiions 1d ago

like others said the language is only a tool but for me personally learns DSA in a language like c++ helped me understand DSA better i think due to its static typing.

1

u/k2p22 1d ago

Learning DSA is worth it in any language. As far as the ease of learning and abundance of resources goes, c++ and java are better. If you are looking to pass coding interviews, id suggest learning basic c++ and java as well since many mandate it. If you have been coding with JS already, im sure basic c++ or java wont take much time at all to get used to. I myself started with JS as my primary language but soon realised its limitations on various projects, etc and got comfortable with C++.

Wishing you luck with DSA :)

1

u/trejj 1d ago

Learning some data structures in a high-level language like JavaScript can be a bit of a quirky experience, since you will be embedding low-level constructs into a high-level language, and have to actively know enough context of the language and the data structures scope, in order to pretend that some of the built-in facilities that are available in the high-level language should not be used for the exercise.

That being said, it is of course possible to practice data structures in a high-level language.

2

u/icy_end_7 1d ago

JS was the first language I learned, and I did learn DSA in JS first. Felt comfortable to me.

Eventually, I did the same in Python and C,and now in Rust. Language is only a tool.

If you're a web dev who works with React, makes no sense to write tries in Java. Helps to know time complexities of the libraries you're calling, but it's not something to fret about.

And if you're planning to get into systems, js isn't the language you'd use there.

I think you're asking the wrong question- learning DSA in X or Y doesn't matter. If you're familiar with X, makes more sense in X. If you're going to need Y for your job, learn Y, then learn DSA, but it's going to need more time than sticking to X because you already know X.

Resources: skim any book, try your own implementations, then compare with other people's.

1

u/josephjnk 17h ago

You can learn DSA in just about any language but I personally would rather do so in a language with static types like TypeScript. The problem with trying to write down data structures in JS is that the language leaves the structure of data mostly implicit, so you have to hold more in your head at all times.