Member-only story
Javascript Interview Questions: Javascript Spread Operator (ES 6)
Javascript Interview Questions # 7
What is the spread operator in Javascript and how can we use the spread operators?
Hello everyone, in this tutorial we will learn about how to use spread operator in javascript with examples.
Spread operator can be used as...variableName
With the help of ES6 in the javascript we can start using destructuring.
While using destructuring we can use spread operator to
- assign remaining values to single variable
- Copy array or clone array
- Combine objects to each other
How can we use spread operator?
While destructuring in the javascript arrays or objects we can pick the variables and assign the remaining ones to single variable
To be able to do that we need to use ...
(spread syntax) before the variable assignment.
Lets have a look at the example below for the array destructuring with spread operator
const arrayValue = [1, 2, 3, 4];// assigning remaining elements to y with three dots
const [x, ...y] =…