类型转换技巧
# 转 Number
let a = '1'
console.log(typeof a) // string
console.log(typeof Number(a)) // number
console.log(typeof +a) // number
# 转 Boolean
let a = '1'
console.log(typeof a) // string
console.log(typeof Boolean(a)) // boolean
console.log(typeof !!a) // boolean
let b = '0'
console.log(!!b) // true
console.log(!!+b) // false, 先转为 Number 再转为 Boolean
上次更新: 2022/08/26, 17:06:25