10 need to know essential JavaScript concepts

Md. Injamul Alam
3 min readMay 6, 2021

--

1. Spread Operator:

The spread operator allows you to spread out elements of an iterable object such as an array, a map, or a set. Using this operator makes the code concise and enhances its readability.

Syntax:

It is denoted by three dots,

For example, see the image:

Uses of the Spread Operator:

There are six ways to use the Spread operator with Array in JS. We can use it to merge or clone an array. Or use it to convert iterables to an array.

  1. Cloning an array:

For using the spread operator main or original array shouldn’t be affected if we changed or copy in the newArray.

Cloning an array into another array without the changed main or original array

2. Merging Array:

Let’s see what happened if we don’t use the spread operator to try to merge an array:

Merging Array without spread operator

When we try to merge an array without the spread operator, we see that the output is a nested or multi-dimensional array. So let’s use the spread operator:

Merging Array with spread operator

Finally, we easily merge the array by using the spread operator.

2. Arrow functions:

If you are new to JavaScript you will listen or see the arrow function. It is a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords. It is also known as anonymous functions (the functions without a name and not bound with an identifier). They don’t return any value and can declare without the function keyword.

Syntax:

  1. If the function have one parameter and simple expression return is not needed:

parameter => expression

For example, see the image:

2. If the function has multiple parameters and multiline statements require body brackets and return needed:

(parameter1, parameter2, parameterN) => {
let n = 1;
return n + parameter1 + parameter2 + parameterN;
}

For example, see the image:

The benefit of uses Arrow Functions:

  1. Reduces the code size
  2. Object transformations

3. ERROR handling with ‘try…catch’:

4. Structured Code with style:

5. Client & Server Caching Balancing:

--

--