I get an "invalid label" error...
I'm kinda new to this. Thanks!
You're creating an object literal, in which could contain name
value pairs. The "invalid label" that you're seeing is from
using incorrect syntax.
Although some browser error messages seem obscure they often actually
provide a better clue to what is happening that it may at first appear.
In this case "invalid label" is a better clue than it appears as in
(expected to correspond with the start of a loop construct of some sort)
and consists of an Identifier followed by a colon. If an object literal
was interpreted in a context where what was intended to be a property
name in the form of a string literal was interpreted as a label (because
of the following colon) then it would be invalid and "invalid label"
would be a very direct and informative error message.
The problem here is likely that a string containing this apparent object
literal definition is begin passed directly to the - eval - function and
object literal definition in the wrong context can be interpreted as a
the contained name value pairs then look like labelled expression
statements. Under this interpretation most object literals would include
syntax errors and so fail to execute but some can happily (if
pointlessly) be executed as a javascirpt Program, e.g.:-
statement surrounding a labelled expression statement consisting of a
number literal expression.
Indeed in the form above the 'object literal definition' cannot be
interpreted as an object literal as it commences with an opening brace,
which is explicitly forbidden as the starting token of an Expression
For an object literal definition to be interpreted as an object literal
it needs to be unambiguously an expression. This can be done by an
action as simple as surrounding the object literal in parentheses (a
statement cannot be contained by the grouping operators, only an
expression may), or making the object literal the right hand side of an
Names have certain rules, for example, names cannot be any
of reserved keywords, cannot start with a number, and can not
include special characters, except an underscore or dollar sign.
This is not true. Identifiers must follow these rules but property names
can consist of any arbitrary sequence of zero or more characters. This
is manifest in the object literal syntax by allowing Identifiers, string
literals and numeric literals to be used as the names of the name/value
pairs (though Mac IE 5 goes belly up if you try to use numeric literals
in that context). The quoted property names above are completely legal,
and probably represent an automated process wrapping the property names
in quotes so that it does not have to think about whether they would
qualify as Identifiers (though making them string literals would still
require the escaping of characters like line terminators).
Values can be a string, number, object, array, boolean, or null.
Or undefined, or functions, regular expressions, dates, etc (if a
distinction is to be drawn between arrays and objects).
For a solution to your problem, this would be a fix: (formatted for
CITY: "Boulder Creek",
If the error had been - expected } or : - then maybe, but this chance
may make the label valid but will then move the error further down the
code to where the second colon is out of place in on expression in a