String padding
JavaScript String padding involves adding characters to the beginning or end of a string to achieve a specified length, in which we have two methods padStart() and padEnd() to add padding to our given string.
Syntax:
string.padStart(targetLength, padString) // String padStart() Method
string.padEnd( targetLength, padString ); // String padEnd() Method
Example: In this example we are using padStart(), result1 has “-Geeks” to total length 10. Using padEnd(), result2 has “Geeks*****” to total length 10.
Javascript
let str1 = "Geeks" ; let result1 = str1.padStart(10, "-" ); console.log(result1); let str2 = "Geeks" ; let result2 = str2.padEnd(10, "*" ); console.log(result2); |
-----Geeks Geeks*****
JS 2017 – ECMAScript 2017
JavaScript (JS) 2017, or ECMAScript 2017, introduced some new features in JavaScript. It enhanced asynchronous programming with async functions, provided shared memory and atomics for improved concurrency, and introduced Object.values() and Object.entries() for streamlined object manipulation. These additions expanded JavaScript’s capabilities, making it more versatile and powerful for modern development.
JavaScript (JS) 2017 new features are:
- String padding
- Object entries() Method
- Object values() Method
- async and await
- Object.getOwnPropertyDescriptors
We will explore all the above methods along with their basic implementation with the help of examples.