系统:Windows 7 VsCode:1.51 Node.js:10.15.3
Part 1:场景说明
+
,但是一旦拼接的部分比较复杂,整个代码也看起来比较费劲,而且易错Part 2: 代码
a = 'you';
b = 'are';
c = 'so';
d = 'good';
e1 = `字符串拼接效果:${a}-${b}/${c}*${d}`;
console.log('e1', e1);
e2 = '字符串拼接效果:' + a + '-'+ b + '/' + c + '*' + d
console.log('e2', e2);
代码截图
运行结果
Part 3:部分代码说明
${}
来引用已定义的变量Part 4:延伸
1. ${} 中支持数值运算,示例如下
a = 'you';
b = 'are';
c = 'so';
d = 1
e1 = `字符串拼接效果:${a}-${b}/${c}*${d+1}`;
console.log('e1', e1);
e2 = '字符串拼接效果:' + a + '-'+ b + '/' + c + '*' + d + 1
console.log('e2', e2);
代码截图及运行结果
本文为原创作品,欢迎分享朋友圈
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有