JS Built-ins
← Object140 / 150
ObjecttoLocaleStringbeginner

toLocaleString() β€” inherited from Object.prototype

πŸ“– Usage Example
// Get locale-aware string representation
const date = new Date(2024, 0, 1)
date.toLocaleString()   // β†’ locale-specific date string
const num = 1234567
num.toLocaleString()    // β†’ '1,234,567'

Use toLocaleString() to get a locale-sensitive string representation of a value, most useful on Date and Number objects.

toLocaleString() β€” inheritance

toLocaleString() is defined on Object.prototype, so all objects inherit it. Subclasses like Array, Number, and Date override it with locale-aware implementations.

Challenge: Verify that plain objects inherit toLocaleString from Object.prototype.

πŸ’‘ Hints (1)
  • β€’ Check hasOwnProperty to determine where toLocaleString comes from