Javascript, write it clean PART 1: variables.

Abdelkader MOUDJAR
2 min readFeb 5, 2022

--

Writing clean code is more than just a code that works, it’s about writing readable & reusable code and keeping it as simple as possible,
while working with a team you will be writing code for a group of people to read and edit, not just to yourself that’s why clean code is very important,

In this article, we’ll go through a couple of tips to write variables cleanly,

Meaningful namings

Just from reading the variable name, you should be able to tell exactly what’s the purpose of it,

Booleans

A boolean should always answer a question.

Avoid Unneeded context

Do not duplicate the object name in its properties, it will only make it harder to read.

Use the same vocabulary

Use pronounceable names

Use searchable names, and Avoid hardcoded values

We can avoid hardcoded values by declaring constants, this will also help us to search for specific code blocks.

--

--

No responses yet