Home > Mobile >  Why does calling pop on an empty array set the length to 0?
Why does calling pop on an empty array set the length to 0?

Time:07-14

Given that the length of the array was already set to 0, why does pop set it to zero again?

Here are the first three steps of the ECMAScript 2023 spec for pop:

1. Let O be ? ToObject(this value).
2. Let len be ? LengthOfArrayLike(O).
3. If len = 0, then
    a. Perform ? Set(O, "length",  0           
  • Related