标签模板字符串
2022-10-28 本文已影响0人
未路过
// ES6: 标签模板字符串
const name = "why";
const age = 18;
// 1.模板字符串的基本使用
const str = `my name is ${name}, age is ${age}`;
console.log(str); //my name is why, age is 18
// 2.标签模板字符串的使用
function foo(...args) {
console.log(args);
}
foo("why", 18, 1.88); // ['why', 18, 1.88]
foo`my name is ${name}, age is ${age}`;
// [Array(3), 'why', 18]
//0: (3) ['my name is ', ', age is ', '', raw: 0:Array(3)]
//1: "why"
//2: 18
image.png