单引号还是双引号

Posted 愉快的一天

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了单引号还是双引号相关的知识,希望对你有一定的参考价值。

console.log("double"); vs console.log(‘single‘);

不应该以编码风格为重点,
而应该以引号内的内容为重点,
比如以下
alert(‘Say "Hello"‘);
alert("Say ‘Hello‘");

更复杂的
alert("It‘s \"game\" time.");
alert(‘It\‘s "game" time.‘);

ES6更喜欢用反斜杠

alert(`Use "double" and ‘single‘ quotes in the same string`);
alert(`The escape the \` back-tick character in a string`);

比如
`\`` === "`" // --> true
console.log("string text line 1\n"+
"string text line 2");
// "string text line 1
// string text line 2"

 

以上是关于单引号还是双引号的主要内容,如果未能解决你的问题,请参考以下文章