Free JavaScript reference · Python timeline

JavaScript ES2017: Async functions and convenient data views

Async/await improves promise-based control flow, objects gain entry/value views, and text padding becomes a built-in operation.

Edition 8 · Published · Editorial review October 26, 2026

Standardized in ES2017 · Syntax

Async/await keeps promise control flow readable

An async function always returns a promise. Inside it, await pauses that function until a value settles, without blocking all other JavaScript work. A rejection is thrown at the await point and can be handled with try/catch.

Use ordinary control flow to transform the resolved value. Returning from an async function fulfills its promise; throwing rejects it. Awaiting independent operations one after another may serialize work unnecessarily.

The example uses a local resolved value rather than a network request. The caller retains the returned promise so completion can be observed. Top-level await is a later module feature, covered in ES2022.

Worked example

Uses ES2017 features · Script

async function report() {
  const count = await Promise.resolve(4);
  console.log(count * 2);
}
const finished = report();

Expected output

8

Example checked with Chromium 151.0.7922.34, Node.js 24.19.0.

Common mistake

await is not legal at the top level of an ordinary script. Async functions do not automatically put CPU-heavy code on another thread.

Try it yourself

Replace Promise.resolve with Promise.reject(new Error("missing")) and add a handler inside report.

Read more: ES2017 specification · MDN explanation and compatibility

Standardized in ES2017 · Built-in method

Object.entries() and Object.values()

Entries expose an object's own enumerable string-keyed properties as key-value pairs. Values expose just the values. These views are useful for small reports and transformations without repeatedly looking up the same keys.

Symbols and inherited properties are excluded. Integer-like keys have specific enumeration ordering, so do not assume every object key follows a general insertion-order rule.

The example uses named fields to keep the ordering simple. If ordering is central to a collection's contract, consider whether an explicit array or Map communicates that intention better.

Worked example

Uses ES2017 features · Script

const scores = {Ada: 8, Mina: 9};
console.log(JSON.stringify(Object.entries(scores)));
console.log(Object.values(scores).reduce((a, b) => a + b, 0));

Expected output

[["Ada",8],["Mina",9]]
17

Example checked with Chromium 151.0.7922.34, Node.js 24.19.0.

Common mistake

Object.entries is not a deep traversal and does not include every property an object could inherit.

Try it yourself

Add a non-enumerable property with Object.defineProperty. Does it appear in the entries view?

Read more: ES2017 specification · MDN explanation and compatibility

Standardized in ES2017 · Built-in method

Padding text with padStart and padEnd

Padding returns a string with a requested minimum length, adding fill text at the beginning or end. It is useful for display labels such as fixed-width identifiers. An already long-enough string is returned with the same contents.

The length is measured in UTF-16 code units rather than displayed character cells. Repeated fill text may be truncated to fit. Use a dedicated layout solution when terminal or visual width is the actual requirement.

Padding creates text; it does not change the numeric value that supplied an identifier.

Worked example

Uses ES2017 features · Script

console.log(String(7).padStart(3, "0"));
console.log("go".padEnd(5, "."));
console.log("long".padStart(2, "0"));

Expected output

007
go...
long

Example checked with Chromium 151.0.7922.34, Node.js 24.19.0.

Common mistake

Padding is not numeric rounding or validation. Do not assume a Unicode code-unit count is the same as visible width.

Try it yourself

Try a multi-character fill such as "ab" and predict which part is truncated.

Read more: ES2017 specification · MDN explanation and compatibility

Recap

Async/await improves promise-based control flow, objects gain entry/value views, and text padding becomes a built-in operation. Check the engines your project supports before adopting new syntax or built-ins.

Read the ES2017 specification →