JavaScript Essentials.

What is ... in Javascript?
It is called the spread operator and used to add old data to a new file as below example.


const newArr = [...oldArr,1,2];

So it adds oldArr elements and 1 and 2 to the newArr.

This is also used if you want to copy the real value of an object instead of reference.
What is destructuring in javascript?
Destructuring is a way of accessing elements from an object or an array as below.

const arr = {1,2,3};
[num1, num3] = numbers;

console.log(num1,num3);//This will print 1 and 2.
What does Javascript Map method do?
The map method returns a new array with result by using all elements of the existing array as below.

const arr = [1, 2,3];

// pass a function to map
const map = arr.map(x => x * 2);

console.log(map1);
// expected output: Array [2,4,6]



Previous
Next Post »

Pages