10 important things should know every Javascript developer

Md. Al-amin Howlader
3 min readMay 6, 2021

--

1. Coding Style:

Coding style actually does not affect the output but it is very important. There are no must rule in coding style but some formats generally maintained by developers. If we write a function we should no space between the function name and parameters. 1 space is good between parameters and curly brace ‘{‘. 2 spaces are good for indentation. Need spaces around operators and a semicolon need after finished a line.

Example:

function add(a, b) {
return a + b;
}

A space need between arguments like that

console.log('my', 'name');

An empty line is good between logical blocks. else{ without line break is good practice.

example:

let number1 = 5, number2 = 7;if(number1 > number2) {
alert(number1, ' is large');
} else{
alert(number2, ' is large');
}

2. Comments:

As a web developer everyone more or less use comments in their code. But everyone does not use comments properly. Comments are mainly used for describing how and why code works.

There are two types of comments single line comments and multi line comments. Single line comments start with // and multiline comments start with /*….*/

Example:

// This is single line comments/* This is
multiline
comments */

Comments can be bad or good. If someone use comments and simply describe code process that is good comment. But longest comments such as describing code as long as the code is too much longer and lost its simplicity then it generally called bad comments.

3. Cross browser testing:

Cross browser testing means run output of code in different browsers such as Chrome, Firefox, Safari, Microsoft Edge, etc. When running code sometimes some browsers didn’t give expected output. That’s why cross browser testing is important.

Why do happen cross browser issues?

In general cross browser issues happen for different types of reasons.

  • Different types of javascript engine: Chrome use V8 engine for run javascript code on the otherhand Firefox use Spider Monkey, Safari use Javascript Core etc. So when run javascript code different engine sometimes give some exceptional result.
  • If browsers have bugs: It is one of important reason for happening cross browser issues. Some times browsers have bugs for that its provide different result.
  • Difference of support and technology features: Every browser doesn’t have similar technology rather than different support system. Some CSS property doesn’t work properly every browser.

Those are common reason for cross browser issues. In production nobody know what type of browser will use their clients. So that before launch application cross browser testing is so important.

4. Error Handling:

One of the most important for all developers is handling errors. Error doesn’t fully depend on how much coding skill you have. If you are a world-class programmer you make error otherwise error happen for different reason but you must face errors.

Try…Catch Syntax:

In try…catch syntax generally use two blocks

Example:

try {
// main code execute here
} catch (error){
// error execute here
}

Firstly execute try{….} part of code. If there is no error then catch{….} part is ignored. If try{…} part has error then catch{….} will execute.

This syntax only works for run time error. If code has syntax error try…catch doesn’t work.

Example:

try {
[:)
} catch {
alert('There is an error');
}

If we run this code catch{…} part alert will not execute because there is a syntax error.

Error Object:

If we pass a parameter of catch like this

try {}catch (error) {
handle error
}

then it gives a object when error is happen. In this object there are mainly two properties. name and message. There is also another property call stack.

Try…Catch…Finally:

This syntax has three blocks.

Example:

try {
// main code execute here
} catch (error) {
// error execute here
} finally {
// this part always execute
}

This is an interesting syntax. Likely same as before but little bit different. Errors happen or not finally part code always execute. If code has no error then try{…} and finally{…} parts will execute else code has error then catch{…} and finally{…} part will execute.

--

--