JS Built-ins
← Object137 / 150
ObjecttoLocaleStringbeginner

toLocaleString() β€” number

πŸ“– 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() β€” Number

Numbers have their own toLocaleString() that formats the number according to locale conventions (e.g., thousands separators).

Challenge: Use Number.prototype.toLocaleString and verify it returns a string.

πŸ’‘ Hints (1)
  • β€’ Number.prototype.toLocaleString formats numbers for the current locale