This post is one in a series of stuff formally trained programmers know – the rest of the series can be found in the series index.
An important term for understanding a stack is that it is LIFO, last-in-first-out, system; namely, the last item you add (or push or bury) is the first item you take out when you retrieve an item (or peek or unbury).
Let's have a look at what a stack would look like:
In this, we added 1, 2, 3, 4, and then 5 and when we read from the stack we read in the reverse order.
Next is the queue, which is very similar to the stack, except where the stack was LIFO; a queue is FIFO, first-in-first-out; so if we put in 1, 2, 3, 4, & 5 into the queue, then we would read them in the same order, i.e. 1, 2, 3, 4, 5.
unshift to add to the beginning of the array (also known as the head) and
pop to remove from the end of the array (also known as the tail).