Home >Web Front-end >Front-end Q&A >What are the backticks used for in es6?
The functions of backticks in es6: 1. Used to parse variables, the syntax is "`${variable name}`"; 2. Used to implement line breaks, the syntax is "`multi-line code`"; 3. Used to call methods, the syntax is "`${method name()}`".
The operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.
1. Variables can be parsed
var name = `张三` var sayHello = `Hello,我的名字叫${name}` console.log(sayHello)
Output result:
2. You can wrap the line
let obj = { name: 'zs', age: 18 } let html = ` <div> <span>${obj.name}</span> <span>${obj.age}</span> </div> ` console.log(html)
The output result is:
3. You can call the function
const fn=()=>{ return '我是fn函数' } let html = `我是模板字符串${fn()}` console.log(html)
The output result is:
[Related recommendations: javascript video tutorial, web front-end】
The above is the detailed content of What are the backticks used for in es6?. For more information, please follow other related articles on the PHP Chinese website!