The next version of ECMAScript was released in 2021. The next features of ES12 or ES2021 that you will learn are: numeric separators and replaceAll
method for strings.
Numeric separators
Numeric separators help the readability of multi-digit quantities. The underscore character ( _
) is used to separate the digits, and does not affect program execution.
The ideal is to separate every 3 digits, to display thousands, millions, billions, etc.
const numero1 = 3501548945console.log( numero1 ) const numero2 = 3_501_548_945console.log( numero1 )
This way you can identify the number quickly.
ReplaceAll method
The replaceAll
method returns a new string, replacing all elements with another one.
This method takes two arguments:
- The pattern to replace, it can be a string or a regular expression.
- The new element that replaces the replaced one.
This procedure was created to solve the problem of the replace
method, which performed the same function of replacing elements, but only once per invocation.
const message = "JavaScript is wonderful, with JavaScript I can create the future of the web."message.replace("JavaScript", "Python")message.replaceAll("JavaScript", "Python")message.replaceAll(/a/g, "*")
Contribution created by Andrés Guano (Platzi Contributor).
Want to see more contributions, questions and answers from the community?