Get Programming with JavaScript - Listing 3.14

Listing 3.14 - Location for a weather app

var location = { "city" : "San Francisco", "state" : "CA", "country" : "US", "zip" : "94101", "latitude" : 37.775, "longitude" : -122.418, "elevation" : 47.000 };

Further Adventures

JS Bin is a program that runs in our browser when we visit the JS Bin website. It declares its own variables to do its work. One of the variables it declares is location. The JS Bin location variable overwrites ours. Renaming our variable to geolocation solves the problem.

Part 2 of Get Programming with JavaScript looks at the problem of overwriting variables in depth and suggests ways to avoid it.