How to declare, interact, and scope variables in JavaScript