当前位置:网站首页>[ES6] template string: `string`, a new symbol in es2015

[ES6] template string: `string`, a new symbol in es2015

2022-07-04 11:37:00 Ruixin's blog

explain : Through an example to illustrate the differences between the three :
Be careful : Symbol of template string [`] It's a button ~ The symbol under
describe :
There is one js Variables store the total number of people :var peopleSum = 88,
It is required to output this sentence in the following format : The total number of people is 88 people

 Mode one : Single quotation marks 

      
  • 1.

console.log(‘ The total number of people is ’+peopleSum+‘ people ’);

 Mode two : Double quotes 

      
  • 1.

console.log(“ The total number of people is ”+peopleSum+“ people ”);

 Mode three : Template string 

      
  • 1.

console.log( The total number of people is ${peopleSum} people );

explain :string It's a template string ,ES2015 New symbols . In the template string var Is a placeholder for variables .
{} inside The expression is still js, Outside, too js .

原网站

版权声明
本文为[Ruixin's blog]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141355201996.html