Some Important Topics of JavaScript

Try…Catch:

Programmers always face errors in their script. That can happen for various reasons. “try…catch” method handles the errors written in code.

Finally:

The work of try catch finally block can be done in two methods. At first, if there is no error, then the try & finally block works. And if there is errors in the code, the block works as first ‘try’ ,then ‘catch’ and lastly ‘finally’.

Coding Syntax in JS:

  1. There must be a space between parameters.
  2. There should be spaces around operators.
  3. A semicolon should be used after each statement if it’s mandatory or not.
  4. Lines should not be very long.
  5. There should be empty line between two blocks of code.

Curly Braces:

There must be spaces used before and after of curly braces. Curly braces are normally written in Egyptian style as the first brace stays in the function declaration line. But if not needed curly brackets should not be used in extra. A line without curly brackets is acceptable if the line is short enough.

Comments:

There are two types of comment. Single line comment and multi-line comment. Single line comments in code starts with ‘//’ (double forward slash symbol). And double or multi-line comments starts with “/*” and ends with “*/” symbol. The comments should be written in good style for the programmers to understand the comments clearly. If not necessary comments should be avoided and programmers should try to write reasonable comments and fully avoid writing bad comments.

Rethrowing:

If any other error occurs in the try area of the code, it is important to catch that. For that reason Rethrowing is used. It is also very important term in try…catch syntax.

Semicolons:

Sometimes in JS it is not important to add semicolons. But it is a good habit to add semicolons after lines where it is important. In the standard JavaScript you can skip the semicolons but you have to use semicolons otherwise.

Indents in JS:

There are two types of indentations. One is horizontal and another is vertical. The horizontal indentation is used usually pressing the tab key where it occurs 2 or 4 spaces and it is a good practice. The vertical indentations are always should be made in conventional form for the code to look readable for any other programmer.

Line Length:

The length of a line should not be very long because that is not suitable for looking the code good and also it sometimes hampers the flow of code. So, line gaps should be make reasonably and for that there are also some shortcuts available now in various code editors.

Nesting Levels:

Nesting level mustn’t be many levels long. For that you can use loops such as for loop, while loop, do…while loop etc. The format of the nested levels must be well enough for other programmers to understand.

Curious Learner