Let’s enlarge the comeliness of JavaScript

Tanvir sazib
3 min readMay 6, 2021

As a programmer code is our snacks, our meal, and our life partner 😆. So, we need to care about our code’s beauty.
Following a specific programming style is often believed to make it easier for programmers to read and understand source code written in that style, as well as avoid creating errors.

Coding style is extremely individual, and everyone has a different preference. Looking back over the code you’ve written when you didn’t have a style guide to follow will help you figure out your own personal style.

But the main focus is our code must be as clean and easy to read as possible.

source: https://javascript.info/

Always use the latest ES version.

Indentation: use spaces instead of tabs, indent using 2 spaces.

Line length: try to cut lines at 80 chars, if possible.

Inline Comments: use inline comments in your code. Use block comments only to document.

Only comment when useful: Don’t add comments that don’t help understand what the code is doing. If the code is self-explaining through the use of good variable and function naming, don’t add a comment.

Semicolon: A semicolon should be present after each statement, even if it could possibly be skipped.

Blocks and curly Braces:if, else, for, while, and try blocks should always use braces and always go on multiple lines.

The function description, conditional, or loop should all be on the same line as the opening brace. The closing brace should be on the line immediately following the block’s last sentence.

if (n < 0) { 
alert('Hi i am in condition');

Whitespace: use whitespace wisely to improve readability. put whitespace after a keyword followed by a (; before & after a binary operation (+, -, /, *, &&..); inside the for statement, after each ; to separate each part of the statement; after each ,.

Naming Conversions: Variable and function names should be full words, using camel case with a lowercase first letter.

const firstVariable = 'Hey I love JavaScript'

Comments: Comments come before the code to which they refer, and should always be preceded by a blank line. Capitalize the first letter of the comment, and include a period in the end when writing full sentences. There must be a single space between the comment token (//) and the comment text.

if (n < 0) { 
alert('Hi i am in condition');
//If The condition is true then it will pop a action with the message.

Bonus: If you are using VS Code, there is an extension named prettier, which Is used to beautify JavaScript codes.