A stack is one of the simplest data structures you will build, and that simplicity is exactly why it is worth building yourself. In this topic you will write a Stack class from scratch in JavaScript: a constructor that sets up the internal storage (commonly an array), a push method that adds an item to the top, a pop method that removes and returns the top item, and a peek method that lets you look at the top without removing it. You will round the class out with isEmpty and size helpers and a print or toString method so you can inspect the contents while debugging, then test everything with a sequence of operations that proves the Last-In, First-Out ordering actually holds.
This matters because almost everything later in the course leans on stacks. Expression parsing, backtracking, recursion and the JavaScript call stack itself all depend on the same handful of constant-time operations you are about to write. Once you have implemented the class, the behavior of those higher-level algorithms becomes much easier to reason about, because you know exactly what happens on each push and pop.
The videos below are implementation-focused rather than JavaScript-specific, so treat them as models of stack reasoning rather than code to copy. While watching, pay attention to three things: which end of the underlying container is treated as the top, how each method handles the empty-stack edge case, and how the author tests the structure after writing it. If a video uses Java, try translating the logic into your own JavaScript class as you go — that translation exercise is where most of the learning happens.
This Geekific video explains, visualizes and implements a stack whose underlying storage is built from queues, walking through how push and pop must be rearranged when the container does not naturally support LIFO. Expect an animated explanation followed by a coded implementation, with the source available on the channel's GitHub repository. It covers the same core operations you are implementing — push, pop and peek — but forces them through an unusual container.
Because the LIFO behavior has to be manufactured here, the video makes the contract of push, pop and peek unusually explicit, which sharpens your understanding of what your own Stack class must guarantee. Geekific's visualize-then-implement format also models the step-by-step method-by-method approach this topic asks you to follow.
The companion Geekific video reverses the exercise: it builds a queue using stacks, visualizing how repeated pops from one stack into another flip the ordering. It explains the approach first and then implements it, again with code linked on the channel's GitHub. Along the way it relies on exactly the primitive operations — push, pop, peek, isEmpty — that you are writing in this topic.
It is the clearest possible illustration of why stack ordering differs from queue ordering, which is the distinction underlying this whole module. It also shows your Stack class being used as a building block, a good preview of why clean helper methods like isEmpty matter.
Dinesh Varyani uses animation to show how pushing every character of a string onto a stack and then popping them off produces the reversed string. The video walks through the algorithm visually before showing the Java code, so you can see the stack grow and shrink one element at a time. It is a short, single-purpose demonstration of stack usage rather than a full class implementation.
It is an ideal first test case for the Stack class you build: simple enough to hand-trace, but it exercises push, pop and isEmpty together. The animation makes the LIFO ordering visible, which helps when you are verifying that your own implementation behaves correctly.
Together these videos reinforce the hands-on goals of this topic. The string-reversal animation and both Geekific implementations repeatedly exercise push, pop, peek and isEmpty, giving you concrete models to translate into the JavaScript Stack class required by MO2, and the string-reversal example doubles as a ready-made test case. The paired stack-from-queues and queue-from-stacks videos directly contrast LIFO and FIFO ordering, supporting MO1, and they also expose how the choice of underlying container affects the cost of each operation, which feeds into the complexity discussion in MO3. Finally, seeing a stack used to drive a small algorithm previews the application-level work on expression evaluation and real-world stack-based features covered in MO4 and MO5.
These videos were chosen from YouTube on October 2, 2026. Each has captions; the player turns them on. Videos on YouTube can be changed or removed — if one no longer plays, tell your instructor. If a player does not appear, use its Watch on YouTube link.