例如:
const a = { valueOf() { return ‘1‘ }, toString() { return false } } const b = { toString() { return true } } console.log(a + ‘1‘); console.log(b + true); console.log(a + b); console.log(a - b );
打印结果:
11 2 1true 0
对象相加隐士转换规则(需要进行转换为原始类型)主要涉及到valueOf() 和toString()方法
原文:https://www.cnblogs.com/doumian/p/12671678.html