Figuring out how javascript works