字符串+数值 数值转换为字符串
var n1='3'+5;//相当于'35',把5转换成字符串5,+号相当于变成拼接3和5
console.log(n1,typeof n1);
数值+字符串
var n4=3+'5';
console.log(n4,typeof n4);
数值+布尔型
var n2=3+true;//相当于3+1=4
var n21=3+false;//相当于3+0=3
console.log(n2,typeof n2);
console.log(n21,typeof n21);
字符串+布尔型
var n3='1'+'true';//相当于字符串‘1true’
console.log(n3,typeof n3);
练习
//假设从后端获取了商品的名称和操作系统,最终显示以这种格式显示 商品名称:xxx 系统:xxx
//+号拼接语句和变量中的数据
var title='AppleMacBook Air';
var os='MacOs';
console.log('商品名称: '+title+' 系统: '+os);
//练习:假设从后获取了一个员工的姓名及其工资,最终显示以下的格式
//姓名:xxx 工资:xxx
var name='abc';
var price='6000';
console.log('姓名:'+name+' 工资:'+price);