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.
Press + to interact
// Original array randomly generatedconsole.log(originalArray);let clonedArray = []
Exercise 2:
Determine the value logged to the console without running it.
Press + to interact
index.js
explanation.txt
let f = () => [..."12345"];let A = f().map( f );console.log( A );
...