2

Is it faster to declare complex data in the JSON conform way:

var data = [ {"x":0,"y":3}, {"x":3,"y":4}, {"x":8,"y":0} ];

Or this way :

var data = [ {x:0,y:3}, {x:3,y:4}, {x:8,y:0} ];

I mean is there any Performance difference ?

Mottenmann
  • 413
  • 1
  • 4
  • 12
  • 4
    Same thing. No difference. Second one is shorter, thus faster to declare. Performance wise, don't even worry about it. Use the second one as general rule, and strings when it makes sense. This is like saying "which is faster, single quotes or double quotes". – elclanrs Nov 28 '13 at 07:25
  • 1
    possible duplicate of [What is the difference between object keys with quotes and without quotes?](http://stackoverflow.com/questions/4348478/what-is-the-difference-between-object-keys-with-quotes-and-without-quotes) – Sarath Nov 28 '13 at 07:44

1 Answers1

3

Usually if declaring an object var data = [ {x:0,y:3} ] this way is preferred because it is faster to write and this need less space but not any major performance difference

But consider a situation you want to assign property name to be reserved words or expression

var data = { class : "Oh class" };
var car = { a*b: "aabb" };

in this situation

var data = { "class" : "Oh class" }    
var car = { "a*b" : "aabb" };

with quotes is preferred since in some IE without quotes it will give error. So quotes is preferred when you want to use a key that’s not a valid JavaScript identifier

Also, the JSON standard (which is not Javascript) always requires double-quotes.

Sarath
  • 9,030
  • 11
  • 51
  • 84