let str1 = '单引号';let str2 = "双引号";let str3 = `反引号`; // 模板字符串(ES6)
特点
- 单引号与双引号只能在一行上,不能换行
- 反引号可以换行,会显示换行空格等
转义符
| 转义符 |
说明 |
| \n |
换行符,n:newline |
| \\ |
斜杠,\ |
| \‘ |
单引号,’ |
| \“ |
双引号,” |
| \t |
缩进,tab |
| \b |
空格,b:blank |
字符串长度
let strZ = '中华人民共和国';let strC = "the People's Republic of China";// 检测字符串的长度console.log(strZ.length); // 7console.log(strC.length); // 30
字符串拼接
let str = '中国';// 中华人民共和国简称中国console.log('中华人民共和国简称' + str);console.log(`中华人民共和国简称${str}`);// 第1届全国人民代表大会console.log("第" + 1 + "届全国人民代表大会");console.log('12' + 12); // 1212console.log('10' + '10'); // 1010console.log('name' + true); // nametrue