DEV Community

Cover image for 5 Dead-Simple Tips to Make Your Code More Readable as a Junior Frontend Developer (And Get Your Pull Requests Approved Faster) πŸŽ‰
Ndeye Fatou Diop
Ndeye Fatou Diop

Posted on • Edited on • Originally published at frontendjoy.com

5 Dead-Simple Tips to Make Your Code More Readable as a Junior Frontend Developer (And Get Your Pull Requests Approved Faster) πŸŽ‰

I have reviewed more than 1,000 frontend pull requests.

I've noticed some common comments made to junior developers, which I also got when starting out. Dealing with these comments often makes the review process longer.

So, if you're a junior developer just starting:

Here are 5 simple tips to make your code more readable.

1. Save meaningful or shared values as constants.Β If a value is significant in your code or used in multiple places, store it in a constant variable in ALL UPPERCASE. This helps give the variable context and makes it easier to locate or modify.

Image description

2. Include the unit in variable names when relevant.Β You saved your meaningful variables in constants. Great πŸŽ‰. Now, make sure to specify the unit if applicable. For example, instead of naming a variable DEBOUNCE_TIME, use DEBOUNCE_TIME_MS to make it more straightforward.

Image description

3. Use the JavaScript numeric separator when possible.Β Improve the readability of numbers like 1000 or 20000 by writing them as 1_000 or 20_000.

Image description

4. Return as early as possible in functions.Β Whenever feasible, exit a function early to enhance the code clarity. This will drastically increase the code readability.

Image description

5. Avoid negative conditionals. Instead of naming a variable isWebsiteNotAccessible, name it isWebsiteAccessible and use !isWebsiteAccessible. Positive conditions are generally easier to understand.

Image description


Thank you for reading this post πŸ™.

Leave a comment πŸ“© to share a tip.

And Don't forget to Drop a "πŸ’–πŸ¦„πŸ”₯".

If you like articles like this, join my FREE newsletter, FrontendJoy, or find me on X/Twitter.

Top comments (0)