Created
May 3, 2025 23:50
-
-
Save HenriqueSilverio/a125e599be2b730708ed772576c86acf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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