Sitemap
JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.

Member-only story

I Rewrote My JavaScript Code Using These 10 Techniques

--

Press enter or click to view image in full size
Image generated by Gemini

Once there was a time when my JavaScript code worked.
This was the trouble.
It worked but it became more and more difficult to read, change and debug.
What began as a function with 10 lines grew to be one with 50.
The seemingly harmless if condition became an intricate series of nested conditions.
The API call became one with multiple levels of try-catch blocks.
Along the way, it got to the point where I found myself writing code which solved today’s problems but created tomorrow’s.
Thus, I did what was simple:
I stopped adding any more features and instead began refactoring my own code.
I did not bring a new framework into play.
I did not add yet another library to the project.
I did not rewrite everything in TypeScript.
Instead, I concentrated on some techniques from plain old JavaScript which helped make my code better.
Here are 10 such techniques.

1. Replace Nested if Statements With Early Returns

--

--

Dr Abdullah Azhar
Dr Abdullah Azhar

Written by Dr Abdullah Azhar

| AI Enthusiast | Researcher | Programmer Doctor exploring the crossroads of programming and artificial intelligence through research, tech, and writing.

JavaScript in Plain English
JavaScript in Plain English

Published in JavaScript in Plain English

New JavaScript and Web Development content every day. Follow to join our 3.5M+ monthly readers.