Few Important Things to Code in JavaScript

Sohel Islam Imran
3 min readMay 6, 2021
  1. Data Type:

Primitive Data Type: Primitive data type is that data which is not an object or method. There are 7 primitive data types: string, number, bigint, boolean, undefined, symbol and null. Though null is a special case for every object, but it’s primitive. Primitive values have something in common that means nothing can affect them or we can say we can not alter them.

Non-Primitive Data Type: Only objects are considered as Non-Primitive data.

2. Try-Catch:

Try-Catch is used to handle errors inside a code. Even if we’re great programmers, we can make mistakes when we write codes. Usually, a code immediately stops when an error occurs. So in that case we can use the Try-Catch function to handle that error. Here is the Try-Catch Script:

try {
// code...
} catch (err) {
// error handling
}

First, Try is applied then if there were no errors then catch will be ignored but if an error occurs then the try will be stopped and catch will show up with the details of the error message.

3. Coding Style:

Coding style is one of the most important things to be a programmer. To become an efficient and high rating programmer one must have to be a good coding practitioner. To become a good coder someone must have to focus on:

  • using curly braces properly.
  • line length shouldn’t be too much horizontally.
  • indentation should be perfect.
  • Using semicolons after each completed line.
  • Not to use too many functions instead try to use less in the best way.
  • And finally follow few style guides to styling like: Google JavaScript Style Guide, Airbnb JavaScript Style Guide, StandardJS, etc.
  • Use ESLint in VS Code to make auto styling of the lines.

4. Comments:

Comments are another important part of coding. To become a good coder someone also has to be a good commentator. Clumsiness in commenting makes the code complex and less attractive to the viewer. Instead of commenting using the relevant name of variable could be a better choice, that makes the code meaningful to any reader. Good comments allow someone to maintain the code well, come back to it after a delay and use it more effectively.

function addWhiskey(container) {
for(let i = 0; i < 10; i++) {
let drop = getWhiskey();
//...
}
}
function addJuice(container) {
for(let t = 0; t < 3; t++) {
let tomato = getTomato();
//...
}
}

--

--

Sohel Islam Imran

I am a MERN-STACK Developer. I am working with React, Node.js, MongoDB and also experience in developing static websites using HTML5, CSS3 and JavaScript.