ES8 (ECMAScript 2017) introduced async/await for better asynchronous programming, Object methods, and string padding features.
June 2017
ES8 (ECMAScript 2017) introduced async/await for better asynchronous programming, Object methods, and string padding features.
Try out JavaScript code examples and experiment with features in the official TypeScript playground.
Open JavaScript PlaygroundSyntactic sugar over promises for writing asynchronous code in a synchronous style.
async function fetchUser(id) {
try {
const response = await fetch(`/api/users/${id}`);
const user = await response.json();
return user;
} catch (error) {
console.error("Error:", error);
}
}
// Usage
const user = await fetchUser(123);Get array of object values and key-value pairs.
const obj = { a: 1, b: 2, c: 3 };
// Object.values
const values = Object.values(obj); // [1, 2, 3]
// Object.entries
const entries = Object.entries(obj); // [["a", 1], ["b", 2], ["c", 3]]
// Iterate over entries
for (const [key, value] of entries) {
console.log(`${key}: ${value}`);
}Pad strings to a specified length with characters.
const str = "5";
// padStart - pad at the beginning
console.log(str.padStart(3, "0")); // "005"
console.log(str.padStart(5, "*")); // "****5"
// padEnd - pad at the end
console.log(str.padEnd(3, "0")); // "500"
console.log(str.padEnd(5, "*")); // "5****"