When should I use double or single quotes in JavaScript?

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

    Technically there's no difference. It's only matter of style and convention.

    Douglas Crockford recommends using single quotes for internal strings and double quotes for external (by external we mean those to be displayed to user of application, like messages or alerts).

    I personally follow that.

    UPDATE: It appears that Mr. Crockford changed his mind and now recommends using double quotes throughout :)

提交回复
热议问题