The right way to use LocalStorage in JavaScript