The reality is slightly more complex... this is the default toPrimitive algorithm that JS uses:
However, if an object has a method named with the well-known symbol Symbol.toPrimitive - then this will be run instead, allowing you to override the default behaviour shown above.
The reality is slightly more complex... this is the default
toPrimitivealgorithm that JS uses:However, if an object has a method named with the well-known symbol
Symbol.toPrimitive- then this will be run instead, allowing you to override the default behaviour shown above.An example of using
Symbol.toPrimitivecan be found in my experiment to add a range syntax to numbers:JS Magic: Making a Range Syntax for Numbers
Jon Randy 🎖️ ・ Mar 24 '23
nice article. I am totally agree with you. It's really hard to understand