Stack Data Structure in JavaScript

Kyle Shevlin
InstructorKyle Shevlin

Share this video with your friends

Send Tweet

In this lesson, you'll learn how to create a stack data structure. A stack is a collection of items that obeys the principle of "last in, first out". Like a stack of plates, we can only access the topmost plate at any time. We must remove that plate before we get down to other plates. This is useful for function calls, hence why it's called a "call stack" in JavaScript.

Joey Ng'ethe
Joey Ng'ethe
~ a year ago

@kyle Why aren't you also using a getter in the isEmpty method? What's the difference?

James Mulholland
James Mulholland
~ a year ago

@joey, I believe this is so you can call stack.length, not stack.length(). Getters give you property access without calling functions.