Javascript Contact list this " " or this ' '?


#1

Hello,

Can someone please explain this to me...
This is from the "What you'll be building" page:

var friends = {};
friends.bill = {
  firstName: "Bill",
  lastName: "Gates",
  number: "(206) 555-5555",
  address: ['One Microsoft Way','Redmond','WA','98052']
};

"Bill", "Gates", and  "(206) 555-5555" have double quotation marks, yet the address presented in an array has single quotation marks ['One Microsoft Way','Redmond','WA','98052'].  

Why?  Aren't the contents of the array a series of strings?

Please help.

Thanks.


#2

Both singleQuote and doubleQuote are valid string delimiters. It is what defines a string literal.

Style guides may have points with respect to which form to use in what context. For instance, as you point out, the property values in the object are double quoted strings. They stand out in the raw code and are easy to spot and read.

Looking at the array, using double quotes in there sort of clutters things, perhaps? This would explain the author's choice of single quotes inside that data structure. Every author adopts their own form of consistency, which is what is important. Consistency.

Consider this case of choosing quotes...

    html_string = '<div class"item">' + item + '</div>';

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.