Array Push Pop
Predict Output Easy
Question
What does this code print?
Code
let arr = [1, 2];
arr.push(3);
let last = arr.pop();
console.log(last, arr.length);
Hint
push adds to the end, pop removes from the end.
Explanation
arr starts as [1, 2]. push(3) makes it [1, 2, 3]. pop() removes and returns 3, leaving [1, 2]. last is 3 and arr.length is 2. The output is: 3 2
Related Resources
Related Lessons
- Arrays
Learn how arrays work.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.