Data Structures and AlgorithmsStacks

A stack follows the LIFO (Last In, First Out) principle. Elements are added and removed from the top only. Commonly used in undo operations, recursion, and expression evaluation.

let stack = [];
stack.push(1);
stack.push(2);
console.log(stack.pop()); // Output: 2