一般一个对象转换为原始值
let a = {}
console.log(+a) //NaN
console.log(`${a}`) //[object Object]
console.log(a + "") //[object Object]
对象转换为基本类型时,优先调用 [Symbol.toPrimitive]转换
let a = {
[Symbol.toPrimitive](type){
if(type == 'number'){
return 10
}
if(type == 'string'){
return 'hello world'
}
}
}
console.log( + a) //10
console.log( `${ a }` ) //hello world