模板字面量

在ES6之前,将字符串连接到一起的方法是+或者concat()方法,如

const student = {
  name: 'Richard Kalehoff',
  guardian: 'Mr. Kalehoff'
};

const teacher = {
  name: 'Mrs. Wilson',
  room: 'N231'
}

let message = student.name + ' please see ' + teacher.name + ' in ' + teacher.room + ' to pick up your report card.';

模板字面量本质上是包含嵌入式表达式的字符串字面量.
模板字面量用倒引号 ( `` )(而不是单引号 ( '' ) 或双引号( "" ))表示,可以包含用 ${expression} 表示的占位符

let message = `${student.name} please see ${teacher.name} in ${teacher.room} to pick up your report card.`;

 



作者:Showdy
链接:https://www.jianshu.com/p/87008f4f8513
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
posted on 2019-04-25 20:25  2015熊出没  阅读(435)  评论(0编辑  收藏  举报