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 is the result of this code: const [a, b, ...rest] = [1, 2, 3, 4, 5]; console.log(rest);?

View

How do you swap variables using array destructuring?

View

Which of the following is a correct way to assign the remaining properties of an object using the rest operator?

View

What happens if you use the rest operator on an empty array? const [a, ...rest] = [];

View

Can the rest operator be used to collect arguments in functions?

View

What is the result of this code: const {a, b} = {a: 10}; console.log(b);?

View

Can you combine both spread and destructuring in the same expression?

View

What is the result of this code: const {a, b, ...rest} = {a: 1, b: 2, c: 3, d: 4}; console.log(rest);?

View

Which of the following is the correct syntax for using the rest operator in a function parameter?

View

What is the purpose of the spread operator when passing arguments to a function?

View

What is the result of this code: const [a, b, ...rest] = [1, 2, 3, 4, 5]; console.log(rest);?

[3, 4, 5]
[2, 3, 4, 5]
[1, 2, 3]
[5]

How do you swap variables using array destructuring?

[x, y] = [y, x]
let [y, x] = [x, y]
[x, y] = [y, x] = []
[x, y] = y, x

Which of the following is a correct way to assign the remaining properties of an object using the rest operator?

const {a, ...rest} = {a: 1, b: 2, c: 3};
const [...rest, a] = {a: 1, b: 2, c: 3};
const {a, rest...} = {a: 1, b: 2, c: 3};
const {rest..., a} = {a: 1, b: 2, c: 3};

What happens if you use the rest operator on an empty array? const [a, ...rest] = [];

rest is assigned null
rest is assigned an empty array
It throws a syntax error
rest is undefined

Can the rest operator be used to collect arguments in functions?

Yes, and it must be the last parameter
No, it can only be used in array destructuring
Yes, but it must be the first parameter
No, rest operators are only for arrays

What is the result of this code: const {a, b} = {a: 10}; console.log(b);?

10
undefined
null
It throws an error

Can you combine both spread and destructuring in the same expression?

No, they are incompatible
Yes, but only with arrays
Yes, with both arrays and objects
Only if using classes

What is the result of this code: const {a, b, ...rest} = {a: 1, b: 2, c: 3, d: 4}; console.log(rest);?

{}
{c: 3, d: 4}
{b: 2, d: 4}
undefined

Which of the following is the correct syntax for using the rest operator in a function parameter?

function add(...nums) {}
function add(nums...) {}
function add([...nums]) {}
function add(nums[]) {}

What is the purpose of the spread operator when passing arguments to a function?

To spread elements of an array into individual arguments
To collect multiple arguments into a single array
To modify the function definition
To concatenate two arrays