Printing data from console while calling method

Hello,

I have a code from exercise: Introduction to Javascript/Array in functions

const concept = ['arrays', 'can', 'be', 'mutated'];

function changeArr(arr){
  arr[3] = 'MUTATED';
}

function removeElement(newArr) {
  newArr.pop();
}

console.log(removeElement(concept));
console.log(concept);

And then I run it I see results like this:

undefined
[ 'arrays', 'can', 'be' ]

I want ask why I can’t print data while I call method removeElement(); on .log();?

you can always call .log() on a function, if the function doesn’t return anything, you get undefined (absence of a return value)

however, .pop() returns the last elements, so if you also return you get the removed element.

6 Likes