Is there a syntax error here?

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: ""
var mary= {
    "phoneNumber":"(650) 888 - 8888";
var contacts=[bob,mary];

I know i am not doing what's been asked to do, but rather, I am trying to see the "contacts" printed out. Why I am getting a syntax error here?

    "phoneNumber":"(650) 888 - 8888";

Why did you use there double quotes around lastName, phoneNumber and email ?

This should be your error


thanks for the reply, but double quote actually isn't an error. but i did what you suggested and removed double quote. then i am still getting the same error.

edit- from what i have learned, double quote can also be used for properties, like..



Hi didnt see that before and i dont know why i should type more like i must :smiley:

Unexpected Token

firstName:"Mary"; //semicolon chage to commata
"lastName":"Johnson"; //semicolon chage to commata
"phoneNumber":"(650) 888 - 8888"; //semicolon chage to commata
"email":""; // remove semicolon


For the record, not to interfere, quotes, either single or double, are all seen by the compiler as single unless there is a string construct in play that uses both.

More importantly, the OP has hit on something revealing, that of string composition of data keys. All property names are by design, string type data. Quotes on single terms are implicit.

firstName: "Bill",
"last name": "Jones"

Since both are already cast as strings, regardless, both of the above are valid property names, or more specifically, *identifierName*s. Quotes make it possible for us to introduce spaces and special characters that are otherwise not allowed.

In a literal sense, we won't write stuff like this, but in a dynamic world anything can happen and JS allows for that, so long as we quote it.


that solves that, thanks.
the quote was actually there in the first object exercise(if i remember correctly).


i knew that quotes are used, but i didn't know the reason. i learned something new today. thank you very much.

so, can you tell me how can someone write spaces or special characters in constructor notation? Or is it okay to write it as normal like..

person.last name=jones;


No. We cannot use any unusual name with spaces in dot notation. Only in subscript, or bracket notation. person['last name'] would yield Jones in this present sense.


understood, thanks.