Question discussion

What is the output of the following JavaScript code?const [x, , ...rest] = [4, 5, 2, 6]; console.log(x, rest[0], rest[1]);

1909Medium DSSSB TGT Computer Science 0 replies

What is the output of the following JavaScript code?

const [x, , ...rest] = [4, 5, 2, 6];
console.log(x, rest[0], rest[1]);
  • A4 2 6
  • B4 5 2
  • C5 2 6
  • D4 2 undefined
Correct answer: A

Explanation

x takes 4, the empty slot skips 5, and the rest element collects [2, 6].

Discussion 0

Nobody has replied yet. Start the discussion!