Home > Web Front-end > Front-end Q&A > What are the backticks used for in es6?

What are the backticks used for in es6?

WBOY
Release: 2022-03-30 18:08:55
Original
2171 people have browsed it

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()}`".

What are the backticks used for in es6?

The operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.

What are the backticks in es6 used for?

1. Variables can be parsed

var name = `张三`
var sayHello = `Hello,我的名字叫${name}`
console.log(sayHello)
Copy after login

Output result:

What are the backticks used for in es6?

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)
Copy after login

The output result is:

What are the backticks used for in es6?

3. You can call the function

const fn=()=>{ return &#39;我是fn函数&#39; }
let html = `我是模板字符串${fn()}`
console.log(html)
Copy after login

The output result is:

What are the backticks used for in es6?

[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!

Related labels:
es6
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template