When should I use double or single quotes in JavaScript?

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

    If you are using JSHint, it will raise an error if you use a double quoted string.

    I used it through the Yeoman scafflholding of AngularJS, but maybe there is somehow a manner to configure this.

    By the way, when you handle HTML into JavaScript, it's easier to use single quote:

    var foo = '
    Cool content
    ';

    And at least JSON is using double quotes to represent strings.

    There isn't any trivial way to answer to your question.

提交回复
热议问题