Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  60] [ 5]  / answers: 1 / hits: 15509  / 11 Years ago, sat, march 16, 2013, 12:00:00

For string literals, are any differences between using apostrophes or using quotes? I'm thinking in regard to performance, functionality, conventions, etc.



To clarify:



'Hello!'


vs.



Hello!


(for want of a more imaginative string)


More From » string

 Answers
10

For me i use it depending on the contents of the string - will the string itself have double quotes or single quotes? if the string has one type of quote, i'll use the other so i don't have to escape it: e.g.:



my string is: <div class=someclass >hello</div>



for the above i'd use single quote so i don't have to escape the single ones:



var str = '<div class=someclass >hello</div>';


otherwise id need



var str = <div class=someclass >hello</div>;


both are perfectly valid, but ones more easy on the coder...


[#79563] Thursday, March 14, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alejandro

Total Points: 231
Total Questions: 102
Total Answers: 107

Location: Jordan
Member since Wed, Jun 17, 2020
4 Years ago
;