Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What does the spread operator do in JavaScript?

View

Which of the following correctly uses the spread operator?

View

What is the output of the following code: const arr = [1, 2]; const newArr = [...arr, 3]; console.log(newArr);?

View

How do you use the rest parameter in function definitions?

View

Which statement about rest parameters is true?

View

What is the output of this function call: function sum(...numbers) { return numbers.reduce((a, b) => a + b); } sum(1, 2, 3);?

View

Can spread and rest operators be used with objects?

View

Which of the following correctly spreads the properties of an object?

View

Can the spread operator be used to copy arrays and objects?

View

What is the result of this code: const [a, ...rest] = [10, 20, 30, 40]; console.log(rest);?

View

What does the spread operator do in JavaScript?

It compresses arrays into single elements
It spreads elements of arrays/objects into individual elements
It merges multiple objects
It removes duplicates from an array

Which of the following correctly uses the spread operator?

let arr = [...[1, 2, 3]];
let arr = [...{a: 1, b: 2}];
let arr = [...(1, 2, 3)];
let arr = [..[1, 2, 3]];

What is the output of the following code: const arr = [1, 2]; const newArr = [...arr, 3]; console.log(newArr);?

[1, 2]
[3, 1, 2]
[1, 2, 3]
[2, 1, 3]

How do you use the rest parameter in function definitions?

By using three dots ... followed by the parameter name
By using two dots .. followed by the parameter name
By using square brackets []
By using parentheses ()

Which statement about rest parameters is true?

Rest parameters collect the remaining elements into an array
Rest parameters are mandatory in function definitions
Rest parameters collect elements into objects
Rest parameters can only be used once in a function

What is the output of this function call: function sum(...numbers) { return numbers.reduce((a, b) => a + b); } sum(1, 2, 3);?

undefined
6
123
NaN

Can spread and rest operators be used with objects?

Yes, both can be used
No, neither can be used
Only the spread operator can be used with objects
Only the rest operator can be used with objects

Which of the following correctly spreads the properties of an object?

let obj = {...{x: 1, y: 2}};
let obj = [...{x: 1, y: 2}];
let obj = {...[1, 2]};
let obj = (...{x: 1, y: 2});

Can the spread operator be used to copy arrays and objects?

No, it only works with arrays
Yes, it creates shallow copies of arrays and objects
Yes, it creates deep copies of arrays and objects
No, it only merges them

What is the result of this code: const [a, ...rest] = [10, 20, 30, 40]; console.log(rest);?

[10, 20, 30, 40]
[20, 30, 40]
[10]
undefined