views:

74

answers:

3

I'm looking at the Google Maps API tutorial, and I see this:

<script type="text/javascript" 
        src="http://www.google.com/jsapi?autoload={'modules':[{name:'maps', version:3, other_params:'sensor=false'}]}"></script>

Why is modules wrapped in single quotes?

+2  A: 

It's a good practice to wrap keys in quotes, even though not strictly required, in order to avoid the possibility of conflicts with JavaScript reserved words.

Imagine if you had class instead of modules - class happens to be a reserved word in JavaScript, even though it is not actually used in the current specification.

Daniel Vassallo
thanks. . . . .
stone
@stone if you are happy with Daniel's response you should accept it by clicking the green tick on the left.
kazanaki
A: 

In fact, in most JSON implementations (because it's actually a JSON string), like jQuery's getJSON, it's obligatory to put all strings, whether they represent values or properties, within double-quotes.

Marcel Korpel
The "double quotes" is the correct way to go for JSON, since they are mandatory in the JSON spec.
Boldewyn
@Boldewyn: thanks, I edited my answer.
Marcel Korpel
A: 

It's not required unless:

  1. The property is named the same as a keyword/reserved
  2. The property has special chars
  3. The object is intended to be used as JSON
Delan Azabani