Summary

In this chapter, we learned about the stack data structure. We implemented our own algorithm that represents a stack using arrays and a JavaScript object, and we learned how to add and remove elements from it using the push and pop methods.

We compared different syntaxes that can be used to create the Stack class, and presented the pros and cons of each one. We also covered how to solve one of the most famous problems in computer science using stacks.

In the next chapter, we will learn about queues, which are very similar to stacks, but use a principle different from LIFO.

Get Learning JavaScript Data Structures and Algorithms - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.