I wrote terrible JavaScript code for years. Here are 5 mistakes I finally fixed. I’ve been working with JavaScript for many years. When I look at my old code now… it hurts a little 😅 Back then, I thought writing clever code meant I was experienced. Turns out, I was wrong. Clear and predictable code matters much more. Over time, my way of writing JavaScript changed a lot. These are some of the mistakes I used to make: • Only coding for the happy path Assumed APIs would always work, respond fast, and return perfect data. • Silent failures Called things like JSON.parse() and hoped nothing would go wrong. • Mutating objects directly I changed data in place and later wondered where the bugs came from. • Loose equality I let JavaScript decide how values should be compared. • Overcomplicated logic Code that looked smart at first but was hard to understand a few months later. • Not thinking defensively I trusted external data instead of checking and protecting my code. 📘 I’ve shared all 7 examples in a short visual PDF below. #reactjs #javascript #webdevelopment #frontend #codingtips #cleanCode #softwareengineering #careeradvice #ReactJS #JavaScript #WebDevelopment #Programming #FrontendArchitecture #CleanCode #SeniorDeveloper #TechLead
This is such a relatable reflection! 😅 Writing “clever” code often backfires—clear, predictable, and defensive coding is what actually makes a codebase maintainable. Fixing habits like handling errors properly, avoiding mutations, and keeping logic simple is pure growth. 💡
The null coalescing operator only considers null and undefined as false. So even if the city is an empty string it will be returned instead of Unknown. In my opinion, it's better to use the OR ( || ) operator in the first example.
For the sake of readability, many seniors still use junior code ;)
If the developer uses JetBrains IDEs, the IDE itself will try to recommend good standards. That's why I love JetBrains.
Helpful
on the first example, nullish coalescing does not behave same with that if check and depending on the requirement you could introduce a new bug.