$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · hard · #117

What is the output?

const a = [1, 2, 3];
a.length = 1;
console.log(a);
  1. [1]
  2. [1, 2, 3]
  3. []
  4. [1, undefined, undefined]
Assigning a shorter length truncates the array in place.
Play Problem Solving ▸