How to Implement a Stack in JavaScript