const obj = {
value: 42,
[Symbol.toPrimitive](hint) {
if (hint === 'number') return this.value * 2;
if (hint === 'string') return `Value: ${this.value}`;
return this.value + 10;
}
};
console.log(+obj);
console.log(`${obj}`);
console.log(obj + 5);
console.log(Number(obj)); Post #2928
3.33K
CHALLENGE
- 🔥 3
- ❤ 2
- 👍 2