Exercise on Spread Operator and Rest Parameters
Get a hang of the spread operator and rest parameters by trying out these exercises. Remember, the point is to think differently and move away from ES5 conventions.
We'll cover the following
Exercise 1:
Make a shallow copy of an array of any length in one destructuring assignment! The given array contains random integers, can be of any length and is called originalArray
. Call the new array you make clonedArray
. Remember to use this exact spelling or your code won’t compile.
If you don’t know what a shallow copy is, make sure you read about it, as you will need these concepts during your programming career. I can highly recommend my article on Cloning Objects in JavaScript.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.