JS 2017 – ECMAScript 2017
Last Updated :
21 Aug, 2023
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.
Method 1: 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);
|
Output
-----Geeks
Geeks*****
Object.entries() returns an array of key-value pairs from an object, enabling easy iteration and manipulation of object properties.
Syntax:
Object.entries( obj )
Example: In this example, an object “obj” has been created with three property[key, value] pairs, and the Object.entries() method is used to return the first property [key, value] pair of the object.
Javascript
let obj = { 0: 'Rahul' , 1: 'Sumit' , 2: 'Rohit' };
console.log(Object.entries(obj)[1]);
|
Object.values() is a method that returns an array of values from an object, useful for extracting and processing object property values during iteration and manipulation.
Syntax:
Object.values( obj )
Example: In this example Object.values() extracts values from person object.
Javascript
let person = {
name: "Nikita" ,
age: 21,
city: "Noida"
};
let result = Object.values(person);
console.log(result);
|
Output
[ 'Nikita', 21, 'Noida' ]
JavaScript async/await is a modern syntax for handling asynchronous operations. The async keyword defines a function that returns a promise, and await pauses execution until the promise is resolved or rejected.
Example 1: In this example, we will see the basic use of async in Javascript.
Javascript
const getData = async () => {
let data = "Hello Geeks" ;
return data;
}
getData().then(data => console.log(data));
|
Example 2: This example shows the basic use of the await keyword in Javascript.
Javascript
const getData = async () => {
let y = await "Hello Geeks" ;
console.log(y);
}
console.log(1);
getData();
console.log(2);
|
The Object.getOwnPropertyDescriptors() method in JavaScript is a standard built-in object which returns all property descriptors of a given object.
Syntax:
Object.getOwnPropertyDescriptors( obj )
Example: In this example, we will see the basic use of the Object.getOwnPropertyDescriptors() method in JavaScript.
Javascript
let geeks1 = {
prop1: "GeeksforGeeks"
}
let geeks2 = {
prop2: "Best Platform" ,
prop3: "And Computer science portal"
}
const descriptor1 = Object.getOwnPropertyDescriptors(geeks1);
const descriptor2 = Object.getOwnPropertyDescriptors(geeks2);
console.log(descriptor1.prop1.enumerable);
console.log(descriptor2.prop2.enumerable);
console.log(descriptor1.prop1.value);
console.log(descriptor2.prop2.value);
console.log(descriptor2.prop3.value);
|
Output
true
true
GeeksforGeeks
Best Platform
And Computer science portal
Share your thoughts in the comments
Please Login to comment...