0

I'm currently learning javascript from the following book 'JavaScript: The Good Parts - O'Reilly Media', which says the following:

The quotes around a property’s name in an object literal are optional if the name would be a legal JavaScript name and not a reserved word. So quotes are required around"first-name", but are optional around first_name.

Question: From my research 'first-name' is not a keyword in javascript, so why does the author say quotes are required around it?

1
  • To rephrase the book: the quotes are required if the name is not a legal JavaScript name or if the name is a reserved word. Commented Jul 28, 2013 at 19:16

2 Answers 2

3

That's because first-name isn't a valid identifier name as defined by ECMAScript :

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

JavaScript is going to see that as var first minus var name.

It's not first-name thats illegal, it's the us of -.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.