原始字符串
·
Yin灏
在所谓的原始(raw)字符串中,其控制字符,例如 ‘\f’、’\n’、’\t’ 等,均不加以解析,当做普通字字符。
let amount = 7;
let str01 = `There are\n ${amount} categories.`;
console.log(str01);
/*
There are
7 categories.
*/
let str02 = String.raw `There are\n ${amount} categories.`;
console.log(str02); // 'There are\n 7 categories.'
// 交错拼接
// ... '___' 是扩展运算符,等价于 '_', '_', '_'
// let str03 = String.raw({raw: 'abcd'}, ... '___');
let str03 = String.raw({raw: 'abcd'}, '_', '_', '_');
console.log(str03); // a_b_c_d
// 交错拼接
let str04 = String.raw({raw: ['apple', 'banana', 'chery', '']},'= 15 ', '=10 ', '=18.');
console.log(str04); // apple= 15 banana=10 chery=18.