Belal Hossain
3 min readMay 8, 2021

--

5 JavaScript things you should know

1. Primitive values: In JavaScript primitive value or data type is a kind of data that is not an object and has no methods. There are 7 primitive data types. They are:

● Undefined​ (undefined), used for unintentionally missing values.

● Null​ (null), used for intentionally missing values.

● Booleans​ (true and false), used for logical operations.

● Numbers​ (-100, 3.14, and others), used for math calculations.

● Strings​ (“hello”, “abracadabra”, and others), used for text.

● Symbols​ (uncommon), used to hide implementation details.

● BigInt​ (uncommon and new), used for math on big numbers.

2. Error Handling: No matter how good we are at coding, we have to face many errors while coding. Errors may occur because of our mistakes, an unexpected user input, an erroneous server response, and for a thousand other reasons.

A syntax construct called “try… catch” is used to handle errors. It allows us to “catch” errors so the script can, instead of dying, do something more reasonable.

3. How “Try… catch” syntax work: “Try… catch” syntax has two main blocks, ‘try block’ and ‘catch block’.

It works like this:

First, the try statement {…} is executed.

If there were no errors, then catch (err) is ignored: the execution complete its work.

If an error occurs, then the try execution is stopped, and control flows to the beginning of catch (err). The err variable will contain an error object with details about what happened.

1. Coding style: Coding style is important for a programmer. Code should be clean, easy and comfortable to read. A good code style is assist the program run easily. Some standard of code style are given below:

· Use one space before the opening bracket.

· There should be space between opening bracket and curly bracket.

· Don’t write a long horizontal line of code. It’s best practice to split them.

· A semicolon should be present after each statement.

· Try to avoid nesting code too many levels deep.

· Declare the functions above the code that uses them.

· Put the closing bracket on a new line, without leading spaces.

· Always end an object definition with a semicolon.

· Use linter tools that can automatically check the style of your code.

Here is a cheat sheet with some suggested rules :

1. Comments: Commenting in code is also important for programmers. Programmer normally do commenting to describe how and why the code work. So, commenting might be obvious, clean and easy to understand. There are two types of comment, ‘good comment’ and ‘bad comment’.

1. Good comment: Good comment is clean, easy to understand and in short. It provides a high-level overview of components, how they interact, what’s the control flow in various situations, how different parts working together etc.

2. Bad Comment: Bad comment is complex, lengthy and not to the point.

Here is some suggestion about commenting:

Comment this:

· Overall architecture, high-level view.

· Function usage.

· Important solutions, especially when not immediately obvious.

Avoid comments:

· That tell “how code works” and “what it does”.

· Put them in only if it’s impossible to make the code so simple and self-descriptive that it doesn’t require them.

--

--