Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HenriqueSilverio/a125e599be2b730708ed772576c86acf to your computer and use it in GitHub Desktop.
Save HenriqueSilverio/a125e599be2b730708ed772576c86acf to your computer and use it in GitHub Desktop.
(new Number()).toString()
// '0'
(new Boolean()).toString()
// 'false'
(new Array('Hello', 'World')).toString()
// 'Hello','World'
(new Date('2025-05-03T23:11:10.312Z')).toString()
// 'Sat May 03 2025 20:11:10 GMT-0300 (Brasilia Standard Time)'
(new Error('Boom!')).toString()
// 'Error: Boom!'
class Money {
constructor(amount, currency = '$') {
this.amount = amount
this.currency = currency
}
toString() {
return `${this.currency}${this.amount}`
}
}
class PhoneNumber {
constructor(aNANP) {
this.phoneNumber = aNANP
}
toString() {
return this.phoneNumber.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3')
}
}
(new Money(5)).toString()
// '$5'
(new PhoneNumber('2607768461')).toString()
// '(260) 776-8461'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment