0
var people = {"name": "Akshar"};
var friends = {name: "Prahlad"};

As shown in the sample code above. I have two objects where one has the 'name' key within double quotes and the other one is without it. When I printed them to the console with dot or bracket notation, it printed the values for both without any issue. So does it make a difference whether I write the keys with the doubles quotes or not? Is there any difference between the two?

Chandral
  • 448
  • 1
  • 3
  • 19
  • 4
    You **need** the quotes (single or double) when the property name does not constitute a valid identifier (like, if you couldn't use the name as a variable name), but otherwise it makes no difference. – Pointy Oct 18 '16 at 13:32
  • No it does not, it does the exact same thing. – Benjamin Gruenbaum Oct 18 '16 at 13:32
  • 2
    @Pointy …with the exception of numeric literals, which are not valid identifier names but also don't need to be quoted as property names. – Bergi Oct 18 '16 at 13:38
  • @Bergi oo yes that's true. (I don't think I've ever done that personally.) – Pointy Oct 18 '16 at 13:39

0 Answers0