My current project involves creating a function that removes the last node of a given list passed in as an argument. The function itself is relatively simple and is shown below.
function popBack(list) {
var current = list.head,
previous;
while (current.next) {
previous = current;
current = current.next;
}
// console.log(current);
// console.log(previous.next);
// current = null;
// console.log(current);
// console.log(previous.next);
previous.next = null;
return list;
}
My confusion lies in the fact that even though I set current
as null
, previous.next
does not seem to be affected and still references the original value of current
. I would appreciate if someone could explain this behavior to me.
Thank you for your help.