Home > Web Front-end > JS Tutorial > body text

Detailed explanation of ES6 string templates

php中世界最好的语言
Release: 2018-03-10 14:19:41
Original
1955 people have browsed it

This time I will bring you a detailed explanation of ES6's string template. What are the precautions when using ES6's string template? Here are practical cases, let's take a look.

    //ES5方式:
    var text = "沧海";
    var whole = "蝴蝶再美,终究飞不过" + text;
    //ES6方式; 并且支持字符串的查找(支持中文),运算;
    var name = "lovely_sr";
    var whole1 = `I love ${name} <br> <b>so much</b><br>`;
    //{}中放表达式;
    var c = 2;
    var d = -3;
    console.log(whole);
    document.write(whole1);
    document.write(whole1.repeat(10));
    document.write("呵呵");
    console.log(whole1.indexOf(name) > 0);
    console.log(whole1.includes(name));
    console.log(whole1.startsWith(name));
    console.log(whole1.endsWith(name));
    console.log(`${c+d}`);
    console.log(`${c}${d}`);
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

Detailed explanation of the expansion operator of ES6

Detailed explanation of the scope and declaration of variables in ES6

The above is the detailed content of Detailed explanation of ES6 string templates. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!