Home>Article>Web Front-end> Detailed explanation of ES6 string templates
This time I will bring you a detailed explanation of ES6'sstringtemplate. What are theprecautionswhen 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}
so much
`; //{}中放表达式; 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}`);
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!