JS Built-ins
← Object141 / 150
ObjecttoStringbeginner

toString() β€” plain object default

πŸ“– Usage Example
// Get string representation of an object
const obj = { a: 1 }
obj.toString()   // β†’ '[object Object]'
Object.prototype.toString.call([])   // β†’ '[object Array]'

Use toString() to convert an object to a string; calling it via Object.prototype.toString.call() reveals the internal type tag.

Object.prototype.toString()

obj.toString() returns "[object Object]" by default for plain objects.

Challenge: Implement getStringRep(obj) that returns the string representation of the object.

πŸ’‘ Hints (1)
  • β€’ Object.prototype.toString() is the default string conversion for objects