不同引号的不同作用。
java中单引号(‘’)包含的数据类型为char型,双引号包含的数据类型为String型;
js中引号包含的就是就是字符串,但是 单引号包含双引号 或者 双引号包含单引号 时要用 \ 转义。
var str = 'This is Jack';
var str2 = "This is Tom";
var str3 = 'This is "Rose"';
var str4 = "This is 'LiLi'";
var str5 = "This is \"Sun\"";
var str6 = 'This is \'Mary\'';
var str7 = "This is \'Lucy\'";
var str8 = 'This is \"Rooney\"';
var str9 = 'This is \\Ronaldo\\';
console.log(str);
console.log(str2);
console.log(str3);
console.log(str4);
console.log(str5);
console.log(str6);
console.log(str7);
console.log(str8);
console.log(str9);
测试结果:
This is Jack
This is Tom
This is "Rose"
This is 'LiLi'
This is "Sun"
This is 'Mary'
This is 'Lucy'
This is "Rooney"
This is \Ronaldo\。
结论:(1)只使用字符的字符串,单引号和双引号没有区别
(2)在单引号包括的字符串中可以直接用双引号,在双引号包括的字符串中可以直接用单引号
(3)如果在双引号包括的字符串中用双引号,需要用反斜杠转义,注意是"\" ;同样在单引号包括的字符串中用单引号,也需要转义“\”
(4)如果要用反斜杠,则输入‘\\’