HighDots Forums  

Trivial Question About Quotes

Javascript JavaScript language (comp.lang.javascript)


Discuss Trivial Question About Quotes in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
philmasterplus
 
Posts: n/a

Default Trivial Question About Quotes - 06-16-2008 , 10:13 PM






When JavaScripting, I've often seen strings wrapped with single-
quotes:
----------------------------------------------------------------
var language = 'English';
----------------------------------------------------------------

However, I prefer double-quotes due to my experience with C++:
----------------------------------------------------------------
var language = "English";
----------------------------------------------------------------

Is there a problem with this? Why is everyone else, including those
who write popular libraries like Prototype.js, using single-quotes? I
know that it's best to stick to a single style when you code(that is,
if your coding style isn't horrible), but is using double-quotes
horrible? Or is it just because you want to use double-quotes inside
strings? :
----------------------------------------------------------------
var example = 'She says, "Hello, world!"';
----------------------------------------------------------------

I know this is a trivial question, but please give me as much
details as possible...^^;;

Reply With Quote
  #2  
Old   
Bjoern Hoehrmann
 
Posts: n/a

Default Re: Trivial Question About Quotes - 06-16-2008 , 10:53 PM






* philmasterplus wrote in comp.lang.javascript:
Quote:
When JavaScripting, I've often seen strings wrapped with single-
quotes:
----------------------------------------------------------------
var language = 'English';
----------------------------------------------------------------

However, I prefer double-quotes due to my experience with C++:
----------------------------------------------------------------
var language = "English";
----------------------------------------------------------------

Is there a problem with this? Why is everyone else, including those
who write popular libraries like Prototype.js, using single-quotes?
There can be a variety of reasons. For example, on some keyboards the
apostrophe is easier to enter (e.g., you might not have to press shift);
in some programming languages variables and most escaped sequences are
interpolated and recognized in "-literals but not in '-literals; quot is
easily confused with two apos characters in some environments; some may
have a convention like `" for markup attributes, ' for script code` so
they avoid misnesting them in onclick="...'...'..." attributes, or their
native language might be using some kind of single quote mark so they
are more used to them. And so on.
--
Björn Höhrmann · mailto:bjoern (AT) hoehrmann (DOT) de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.