When should I use double or single quotes in JavaScript?

前端 未结 30 3433
攒了一身酷
攒了一身酷 2020-11-21 05:02

console.log("double"); vs. console.log(\'single\');

I see more and more JavaScript libraries out there using single quotes when ha

30条回答
  •  执念已碎
    2020-11-21 05:11

    Section 7.8.4 of the specification describes literal string notation. The only difference is that DoubleStringCharacter is "SourceCharacter but not double-quote" and SingleStringCharacter is "SourceCharacter but not single-quote". So the only difference can be demonstrated thusly:

    'A string that\'s single quoted'
    
    "A string that's double quoted"
    

    So it depends on how much quote escaping you want to do. Obviously the same applies to double quotes in double quoted strings.

提交回复
热议问题