Arrays

Push Return Value

Push Return Value

push changes an array by adding an item to the end. Its return value is the new length of the array, not the array itself.

That distinction matters when you save the result of a mutating method. Storing the wrong value can turn a list into a number in later code.

Read this code:

js
const queue = ["build", "test"];
const result = queue.push("deploy");

Your task: Before running anything, predict the value stored in result and the final number of items in queue.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Push Return Value

push changes an array by adding an item to the end. Its return value is the new length of the array, not the array itself.

That distinction matters when you save the result of a mutating method. Storing the wrong value can turn a list into a number in later code.

Read this code:

js
const queue = ["build", "test"];
const result = queue.push("deploy");

Your task: Before running anything, predict the value stored in result and the final number of items in queue.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Console

Run code to see output.