You are debugging a piece of code and encounter a variable declaration let [a, b, ...rest] = [10, 20, 30, 40, 50];. What will be the value of rest?

  • [30, 40, 50]
  • [10, 20]
  • [20, 30, 40, 50]
  • [undefined, undefined]
The value of rest will be [30, 40, 50]. This code uses destructuring assignment to assign the first two elements to a and b, and the rest of the elements to rest using the rest parameter (...). So, a will be 10, b will be 20, and rest will contain [30, 40, 50].
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *