What is the output of the following code? “`js const arr = [1, 2, 3]; const [a, , b] = arr; console.log(a, b); “`

JavaScript Associate Medium

JavaScript Associate — Medium

What is the output of the following code? “`js const arr = [1, 2, 3]; const [a, , b] = arr; console.log(a, b); “`

Key points

  • Destructuring assignment allows specific elements of an array to be assigned to variables.
  • The empty space between commas in the destructuring assignment skips elements.
  • The order of variables in the assignment corresponds to the order of elements in the array.

Ready to go further?

Related questions