Stacks let us add items to it and the last item that’s added is the first item that can be removed.
Queues let us add items to it and the first item that’s added is the first item that can be removed.
push method lets us add items to the end of the array.
pop method lets us remove the last item from the array.
For instance, we can create a stack by writing:
const stack =  const pushed = stack.push(1, 2) console.log(stack) const popped = stack.pop() console.log(stack, pushed, popped)
push method lets us append the items that we passed in as arguments into the
And it returns the last item that’s been appended to the array.
pushed is 2.
pop method lets us remove the last item from thr
And it returns the popped item.
popped is 2 and that’s what’s removed from the array.
[1, 2] when logged from the first console log.
And the 2nd console log will log
 as the value of
We use the
push method to append items to the queue as we do with stacks.
And we can use the
shift method to remove the first item in the array.
For instance, we can write:
const queue =  const pushed = queue.push(1, 2) console.log(queue) const shifted = queue.shift() console.log(queue, pushed, shifted)
Therefore, the first console log logs
[1, 2] as the value of
And in the 2nd console log,
pushed is 2 and
shifted is 1.
shift returns the element that’s added to the beginning of the array.
To get the size of either data structure, we can just use the
So we can log
queue.length respectively to get their sizes.
And we get their sizes with the