在以前es5的时候,使用字符串只能用‘或者“来包裹,而且在字符串拼接的时候只能用+拼接,如下
var single = "hello world";
var single1 = 'hello ' +
'world ' +
'my ' +
single +
'name ' +
'is ' +
'asim';
复制代码
如果中间有变量拼接就会相对麻烦,但是在es6中,有很方便的写法,现在可以使用${variable_name}语法在``模版字符串中插入变量。
let name = "asim";
let multi = `
hello
world
my
name
is
${name}
`;
console.log(multi);
复制代码
总结
``模版字符串方便多行字符串和变量代换