Javascript Clean Coding : Tips for Beginners

Pulack Hassan
2 min readNov 3, 2020

Clean coding is mandatory for professional programming. Here clean coding refers to the coding style that is clean to see and easy to read. Clean coding is also called art of programming. Clean coding express the programmer’s versatility.

Here is some suggestions for javascript clean coding:

Meaningful names of variables, functions and methods: We should use meaningful name while programming. It will increase the understandability and readability of coding. The readers will able to understand easily why or how the variables or functions are used and executed.

Increase the readability of syntax: Always try to make the syntax more cleanly. Space between parameters , space after function/if/else/for/do/while, No space between the function name and parentheses between the parentheses and the parameter, spaces around a nested call etc. make the code more precise.

Curly braces: You have to use curly braces while using function or loops or conditions. If we use the opening brace on the same line as the corresponding keyword — not on a new line, it will look clean.

Line length: No one likes to read a long horizontal line of code. If you want to clean coding then don’t make a line so long . It’s best practice to split them.

Semicolons: Each statement should be end with a semicolon. Though sometimes the statement works without using semicolons. But it is mandatory to use a semicolon.

Nesting levels: It is better to avoid nesting code too many levels deep.

Comments: There are two types of comment- single line and multi line. It is used for describe how and why the coding is created. Comment increase the understandability of coding and allows us to maintain the coding. But we should not misuse the comments- that can make the codes messy. So use the comments where it be needed to use. Sometimes clean coding without comments is the best describer of itself.

Style guides: Style guide contains the general rules about how to code. When all members of a team use the same style guide, the code looks uniform, regardless of which team member wrote it. Some popular choices:

Automated Linters: Linters indicate the tools that automatically check the code and suggest improving styles. The great thing about them is that style-checking can also find some bugs, like typos in variable or function names. Because of this feature, using a linter is recommended even if you don’t want to stick to one particular “code style”. Some popular linter tools are: jslint, jshint, eslint.

--

--