一.数据转换
整数型和boolean型转为字符串类型
字符串类型转换为整数类型
其他类型转为boolean类型
- 非字符串类型转换为字符串类型
let a = 5;
let b = 6;
b = (String)b; //使用类型进行强转
a.toString(); //使用方法进行强转
console.log(typeof a) //string
- 字符串类型转换为整数类型
let a = 5;
a = Number(a); //使用数据类型进行强转
let b = 5;
b = parseInt(b);
console.log(typeof b) //整数类型
- 其他类型转为boolean类型
直接使用boolean()进行转换
let a = '';
a = Boolean(a);
console.log(typeof a); //bool类型