Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )
-
Take variables
var name = "liyang"; var age = 23; console.log(`I am ${name},I ${age} years old`)
如果想用到反引号,用斜杠转义 var name = "liyang"; var age = 23; console.log(`I \`\`am ${name},I ${age} years old`)
-
Display multi-line strings
$('#root').html(` <ul> <li>一</li> <li>二</li> <li>三</li> </ul> `)
<Ul> tag will be in front of a line break. If you want the first row and the end row of line feeds, spaces, etc. is removed, using methods trim.
$('#root').html(` <ul> <li>一</li> <li>二</li> <li>三</li> </ul> `.trim())
-
Embedding a plurality of variables are used
var x= 1, y = 2; console.log(`${x} + ${y} = ${x + y}`)
var x = 1, y = 2;
console.log (${x} + ${y * 2} = ${x + y * 2}
)var obj = {x: 1, 2};
console.log (${obj.x + obj.y}
); -
call function
function func(){ return 'Hello'; } console.log(`${func()} World`);