Back to questions
JuniorTheoryCommon
What does the program print?
const a = [1, 2];
const r = a.push(7);
console.log(r, a.length);3 3
- Expecting
pushto return the added element7: it returns the new length of the array, which is3. - Expecting
TypeErrorbecauseais aconst:constonly forbids assigning a new value toa; the array itself can still change.
- What does
popreturn when it is called onaafterwards? - Which method adds an element to the start of an array?