• Skull giver@popplesburger.hilciferous.nl
    link
    fedilink
    arrow-up
    0
    ·
    2 months ago

    Same is true for JavaScript’s namesake, Java; Object has a toString method, so everything but primitives (int, long, etc.) must have a toString method (and primitives sort of have one too in a roundabout way).

    I think JavaScript’s toString also serves another function, namely to have some form of fallback when doing operations on what should be incompatible types. [] + "", for instance; JavaScript will call toString() to do type conversion when the nearest matching type is a String.