.push() - don’t get the same array, get a number

Hello i have been experimenting with utilizing the pop function. I know it stores the last value, so if i push the removed value back onto the array i should get the same result. However, I don’t get the same array, in fact I get a number: 5.

Here is my code

const chores = ['wash dishes', 'do laundry', 'take out trash', 'cook dinner', 'mop floor'];
const removed = chores.pop();
console.log(chores); 
console.log(removed);
console.log(chores.push(removed));

and here is what I am getting as a result:

[ ‘wash dishes’,
‘do laundry’,
‘take out trash’,
‘cook dinner’,
‘mop floor’ ]
[ ‘wash dishes’, ‘do laundry’, ‘take out trash’, ‘cook dinner’ ]
mop floor
5

Popping returns for assignment the element just taken off the array. The array is mutated, but not returned.

Pushing mutates the array by appending a value. The array is mutated but, again, not returned. What is returned is the new (now current) length of the mutated array.

 > a = []
<- []
>  while (a.length < 10) {
       a.push(Math.floor(Math.random() * 10 + 1))
   }
<- 10
 > a
<- (10) [10, 9, 2, 7, 4, 1, 1, 3, 1, 2]
2 Likes