Function objToString

  • The objToString() method returns a string representing the object. This explicitly always calls the Object.prototype.toString() method.

    An object's toString() method is most commonly invoked when that object undergoes:

    • explicit type conversion to a string (for example, String(myObject))
    • implicit type coercion into a string (for example, myObject + "hello world")

    Parameters

    • value: any

      The object to be converted into a string

    Returns string

    A string representation of the object

    objToString(new Date()); // [object Date]
    objToString(new String()); // [object String]

    // Math has its Symbol.toStringTag
    objToString(Math); // [object Math]

    objToString(undefined); // [object Undefined]
    objToString(null); // [object Null]