Tuesday, 10 September 2013

When is it correct to use quotation marks when defining an object literal?

When is it correct to use quotation marks when defining an object literal?

In pure JavaScript, is there a difference between the two snippets below?
// Snippet one
var myObject = {
"property":"something"
}
// Snippet two
var myObject = {
property:"something"
}
MDN and the Google JavaScript style guide suggest that the two are
equivalent.
The JSON specification mandates the use of quotation marks.
When is it correct to use quotation marks when defining an object literal,
if at all? Does it imply/make any difference to the interpreter? Is it
simply a case of choosing one or the other and being as consistent as
possible?

No comments:

Post a Comment