why “Single-quoted string preferred over double-quoted string.” in js?

前端 未结 4 2344
不知归路
不知归路 2021-02-19 01:22

While using gjslint, I got a hint: \"Single-quoted string preferred over double-quoted string\".

So why? I\'m a little confused with this. Why single-quoted preferred?

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-19 01:52

    In terms of performance, according with http://jsperf.com you get almost the same performance for both in some browsers, in others you get the same performance.

    There's a lot of tests in jsperf and all of them get almost the same result:

    • http://jsperf.com/double-or-simple-quote
    • http://jsperf.com/quotes-compare
    • http://jsperf.com/jquery-double-vs-single-quotes
    • http://jsperf.com/search?q=quote

    In conclusion I think using single or double quotes is just a matter of taste and not a matter of performance.

    Regards.

提交回复
热议问题