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 - Jan 22 - - Dev Community

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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .