When should I use double or single quotes in JavaScript?

前端 未结 30 3448
攒了一身酷
攒了一身酷 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:16

    I would use double quotes when single quotes cannot be used and vice versa:

    "'" + singleQuotedValue + "'"
    '"' + doubleQuotedValue + '"'
    

    Instead of:

    '\'' + singleQuotedValue + '\''
    "\"" + doubleQuotedValue + "\""
    

提交回复
热议问题