- 字符串转Number
1.1.显式转换
const str = '99'
console.log(typeof Number(str)) //number
1.2.隐式转换
console.log(typeof (str*1)) //number
2.Number转字符串
2.1.显示转换
const num = 99
console.log(typeof String(num)) //string
2.2.隐式转换
console.log(typeof (num + '')) //string
3.布尔值转换
3.1.显示转换
使用!!来转换,或者使用构造函数Boolean()来转换
3.2.隐式转换
Number类型中,只有0为false,其他正数负数小数都为true
String类型中,只有''和不传值为false,其他都为true
引用类型都为true
但即使都为true,用==比较时也会为不相等
8463

被折叠的 条评论
为什么被折叠?



