Javascript Smart Coding Style
Javascript Smart Coding Style
Introduction :
In a programming language, sorting or arranging these codes is called smart coding.
Suppose you are a programmer, you write your code in one of the editors and if you put the codes in a random way and the codes are working properly but no other programmer or developer saw the codes you wrote and could not understand any of your code for awkwardness. Or you are working in a programmer’s team and they could not understand anything by looking at your code, then you are unable to collaborate for that team.
Also, suppose you have coded and after a long time want to see the codes you have made before, but you can’t understand anything by looking at the code of your mess or you can’t understand what the code is working for, so the codes are beautiful. Keeping it organized is called smart coding.
All programming languages have some rules and regulations for this smart coding. Similarly, JavaScript also has certain smart coding rules and regulations
Syntax -
~ A space between parameters
~ No space between the function name and parentheses between the parentheses and the parameter
~ Curly brace { on the same line, after space
~ Indentation 2 spaces
~ Spaces around operators
~ Space after for/if/while…
~ A semicolon; is mandatory
~ A space between parameters
~ An empty line between logical blocks
~ Lines are not very long
~ } else { without a line break
~ Spaces around a nested call
Curly Braces:-
If any Curly Braces in any function or conditional experiment
If you want to use, then the executed lines have to be written after 2/3 space in the next line
Line Length
Semicolons:-
JavaScript Semicolons are used as an experiment clause. Semicolons in JavaScript are not mandatory, many programmers do not use Semicolons. JavaScript Semicolons are used as an experiment clause. Semicolons in JavaScript are not mandatory, many programmers do not use Semicolons.
Nesting Levels:-
The code for nesting levels or the next lines have to be given in 2/3 space or tab before it
Function Placement:-
If any other function of a function is executed, there must be a gap between the next function
Javascript Comments
When you add Comments to your script, the JavaScript engine ignores those lines or those comments, meaning the JavaScript engine does not execute them.
To add comments, you need to give two forward slash(//) and then give your message.
When I work on a project, a lot of people have to work together so that when someone reads your code, they can better understand what you are writing the code for and how your code works so that they don’t have trouble understanding it. There are very few places where you can write a message through Comets.
We can commit any code example
// let name = “Lancer Abir”
Then it became line comments. JavaScript will no longer execute this line piece.
Comets are usually of two types
- Single-Line Comments
- Multiple Line Comments
1 single line comets
If you want to comment on just one line, you have to use single line comments
// Single-line comments
2 multiple line comets
If one or more lines are to be commented, multiple lines are used
/ **
* Multiple line comets
* Double line
* /