← All Exercises

Stack Implementation

intermediatejavascript~15min

Background

Stacks are used in function call management, expression evaluation, backtracking algorithms, and undo mechanisms.

Problem

Create a Stack class with push, pop, peek, and isEmpty methods that follow Last-In-First-Out (LIFO) ordering semantics.

Input

No input; the stack is initialized empty and items are added via push.

Output

A Stack instance with standard LIFO operations.

Sample tests

Sample 1

Input: push(1), push(2), pop()
Expected: 2

Your solution

Learning objective

Understand LIFO data structures and implement them using underlying array storage.