When should I use double or single quotes in JavaScript?

前端 未结 30 3442
攒了一身酷
攒了一身酷 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条回答
  •  -上瘾入骨i
    2020-11-21 05:10

    If your JavaScript source is

    elem.innerHTML="It\";
    

    the HTML source will be:

    It's a Smiley
    

    Or for HTML5

    It's a Smiley
    

    JavaScript allows arrays like that:

    var arr=['this','that'];
    

    But if you stringify it, it will be for compatibility reasons:

    JSON=["this","that"]
    

    I'm sure this takes some time.

提交回复
热议问题