When should I use double or single quotes in JavaScript?

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

    There are people that claim to see performance differences: old mailing list thread. But I couldn't find any of them to be confirmed.

    The main thing is to look at what kind of quotes (double or single) you are using inside your string. It helps to keep the number of escapes low. For instance, when you are working with HTML content inside your strings, it is easier to use single quotes so that you don't have to escape all double quotes around the attributes.

提交回复
热议问题