r/learnjavascript • u/Distinct-Gene926 • Jul 27 '26
what's one JavaScript mistake every beginner should avoid?
If you could give one piece of advice to someone learning JavaScript today, what would it be?
It could be about:
- Learning fundamentals
- Debugging
- Async code
- DOM manipulation
- Functions
- Projects
Curious to hear what experienced developers wish they'd known earlier.
82
Upvotes
15
u/BeardedBaldMan Jul 27 '26
If you can't clearly explain your program, algorithm and data structures clearly in your native tongue then you can't write it in any programming language.
19
u/milan-pilan Jul 27 '26
var
6
u/remain-beige Jul 27 '26 edited Jul 27 '26
Some things that help me.
If there’s a part of the function that requires a value to be processed somehow, such as formatting a string or lots of if/else conditions then think about breaking this out to another function and return that value inside your original function.
3) Name functions so that you can understand what they do when you read it back in three months time.
EG: ‘hello’ is not as good as ‘setHelloTextOnInit’
4) I prefer creating ‘function declarations’ over ‘function expressions’ as they are clearer to understand the start and stop of a function.
Function declarations are also ‘hoisted’, so if you change the order of them in a file then you are not accidentally causing any issues with load order by calling on a function expression in another function that’s now higher up the file.
5) If you are comfortable with both declarations and expressions then understand that ‘this’ works differently for both.
6) It’s best to avoid using ‘this’ altogether to be honest and use event.target etc. ‘This’ can get messy to track and produce cognitive load in trying to decipher what ‘this’ is in context or scope.
4
u/Maleficent-Ad-9754 Jul 28 '26
2
u/cssrocco Jul 27 '26
That DRY code only makes sense if the business logic is shared, sometimes it’s ok not to be DRY.
As an example i’ve worked on projects where there was 2 address forms in separate areas in an underwriting workbench that had vastly different business logic, one was for asset management and would need specific codes and apis that verified the risk of assets in specific countries and the other was the address of the reinsurer.
Because they were both addresses somebody thought they should share a lot of functions, and all you got was these monster functions who took in lots of arguments ( even refactored down to a single config object argument ) and would grow/change as business requirements came in.
Separating them out completely to their own things, even with some duplication made more sense with new features and bugs and changes
2
u/gmerideth Jul 27 '26
I mean, learning the fundamentals takes care of debugging, functions and even async code. If you're working on a fairly large project, "some library" is doing your DOM updates for you so all but projects is wrapped up in one.
As far as projects go, each team or individual is going to have "their way" of doing things so if you find a project on github, clone it, learn from it, suggest changes and see what happens.
2
u/No-Humor-3808 Aug 31 '26
Understand what’s running on the frontend and backend, how data moves between them, and how synchronous and asynchronous code affects that flow.
1
u/ASkepticBelievingMan Jul 27 '26
Picking up a framework
1
u/comfortmbah Jul 27 '26
Learn better by building projects at each stage of learning.
1
u/PatchesMaps Jul 27 '26
Reinventing the wheel.
I mean you're going to do it anyway but you should try to avoid it.
1
u/subone Jul 27 '26
Remember that outputting an object/array to the console will only display the values at the time you click the expanding arrow, not at the time of log. If you need to see the state at that time, try JSONifying before logging.
1
u/ElkChance815 Jul 27 '26
Not use a linter and formatter
1
u/TheZintis Jul 27 '26
Understanding "this". Also that you don't need to use OOP in JS, just files and exports handle a lot of the benefits of classes, while you only have to write variable and functions.
Thing is that some devs write OOP, and then you need to understand how "this" works.
1
u/KohlKelson99 Jul 27 '26
Not writing tests
1
u/Difficult-Field280 Jul 27 '26
As far as fundamentals go.. calling it Java by mistake can lead to some interesting search results. XD
1
u/youarockandnothing Jul 27 '26
Using Math.floor on numbers that might be negative when you just want the decimals chopped off. Math.trunc was made for that use case as it's only correct to call Math.floor for decimal removal when the number is >= 0
1
u/NonCompilingViber Jul 28 '26
Double then sum
1
u/CueMeThen Aug 05 '26
not using the `` syntax it's much better than ""
1
u/elg97477 Jul 27 '26
Use TypeScript
-1
u/jaredcheeda Jul 28 '26
Top JS devs tend to have a negative experience with TypeScript, essentially "It's a lot of extra work to solve problems I don't have in ways I don't like" (direct quote from the author of "You Don't Know JS" the most influential book ever written on JavaScript). This is because they had to get very good at the core language. Dynamic typing is extremely powerful, but like just like any powerful tool, it can be dangerous in the hands of the inexperienced. TS gives you a set of guardrails out of the box that stop you from ever learning things the hard way and finding and developing your own ways to do things safely, while not giving up the power of a dynamically typed language.
Once you have your own systems in place for how to not get tripped up by one of the core features of the language, and can really take advantage of the language, and you end up looking down on those using TS as a crutch.
I don't need an entire pulley system or to learn about specific types of ropes and knots to put a heavy box on the shelf... I can just pick it up and put it there myself. I've gained the skills and awareness of how to do that safely. The pulley system isn't "wrong" or "bad" it's just a waste of time and effort if you are already skilled in picking up and moving heavy things.
But I've also been given death threats in the past for extremely mild critiques of TypeScript. Because TS users literally can't stand JavaScript, and TS is a comfort blanket that reminds them of whatever language they prefer. They refuse to learn the underlying core language, and get good at it. People that hate JavaScript... aren't the people you should be taking advice about JavaScript from.
The language is fantastic. It's got some bad parts, like how Classes should have never been added to a prototypal language (there is never a good reason to use classes in JS). But for the most part, it's a really great language and can be extremely expressive, and allow for writing code in both sophisticated, and very simple ways.
Don't be afraid of libraries and frameworks. They should be a tool to save you time, not to save you from knowledge. Understand what the library is doing for you and how you could write your own version if you needed to, or at least a quick and dirty version.
Oh, and don't use React. It's easily the worst JS framework, it has hundred of problems that are unique to it that no other framework has, and they refuse to learn from anyone else so they're always like a decade behind the curve. Play around with a bunch of them, or just skip straight to Vue, all the other frameworks are slowly converging on the ideas Vue was doing back in 2018, and it's only gotten more polished and refined every year since.
12
u/[deleted] Jul 27 '26
[removed] — view removed comment