All examples

Stack (class), .

A LIFO stack built as a class with push / pop / peek.

stack.js
class Stack {
  constructor() { this.items = []; }
  push(x) { this.items.push(x); }
  pop() { return this.items.pop(); }
  peek() { return this.items[this.items.length - 1]; }
}
const s = new Stack();
s.push(1);
s.push(2);
s.push(3);
s.pop();

What to watch

The instance shows its class name and items array; push and pop animate the LIFO discipline in the data view.

Reading stack (class)on a page only gets you so far - code is a process, and the process happens at runtime where you can't normally see it. In NeonFlow, this exact program runs step by step: every call opens a frame, every branch picks a path, and every value moves through memory in front of you. That's the fastest way to actually understand how stack (class) works.

Run stack (class) yourself

Open NeonFlow, paste this code (or any of your own), and scrub through it one step at a time.

Open NeonFlow