JS Built-ins
← Object142 / 150
ObjecttoStringintermediate

toString() β€” Object.prototype.toString.call(null)

πŸ“– 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.call() β€” type detection

Object.prototype.toString.call(value) is a reliable way to detect the type of any value. It returns tags like "[object Null]", "[object Array]", etc.

Challenge: Use Object.prototype.toString.call() to get the type tag of null.

πŸ’‘ Hints (1)
  • β€’ Object.prototype.toString.call is the classic type-detection idiom