What is the output of the following? “`js const [a, b, …rest] = [1, 2, 3, 4, 5]; console.log(rest); console.log(typeof rest); “`

JavaScript Developer Hard

JavaScript Developer — Hard

What is the output of the following? “`js const [a, b, …rest] = [1, 2, 3, 4, 5]; console.log(rest); console.log(typeof rest); “`

Key points

  • The rest parameter `...rest` gathers all remaining elements into an object.
  • The output is an array `[3,4,5]` because `rest` contains the remaining elements.
  • The type of `rest` is 'object' due to the rest parameter behavior.

Ready to go further?

Related questions