3. Consider the following linked list and pop operation in JavaScript:
class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
class LinkedList {
constructor() {
this.head = null;
}
push(value) {
const newNode = new Node(value);
if (!this.head) {
this.head = newNode;
return;
}
let current = this.head;
while (current.next) {
current = current.next;
}
current.next = newNode;
}
pop() {
if (!this.head) return null;
if (!this.head.next) {
const val = this.head.value;
this.head = null;
return val;
}
let current = this.head;
while (current.next.next) {
current = current.next;
}
const val = current.next.value;
current.next = null;
return val;
}
}
const list = new LinkedList();
list.push(10);
list.push(20);
list.push(30);
const poppedValue = list.pop();
console.log(poppedValue);What will be printed?