Sitemap

JavaScript ES8: A crash course on modern JS

2 min readApr 24, 2022

--

Summary — updated April 2022

Babel

One of the biggest changes from ES5 is that ES6 JavaScript is not able to be compiled directly in browsers. We need to use a transpiler called Babel.js to produce compatible JavaScript that the older browsers can read.

Babel allows you to use ES6 features and syntax in your project and then translates it to ES5 so that you can use it in production.

Read: How to: use Babel once your project is built.

The Most Important ES2018 Updates

ES8 — Rest / Spread for Objects

This feature builds off of updates from ES6 so we can use rest/spread syntax for objects. The spread operator enables us to create a clone of an Object so we can modify the original more easily.

This feature should not be used at the end, or it will result in an error.

let myObj = {
a:1,
b:3,
c:5,
d:8,
}

// we use the rest operator to grab everything else left in the object.
let { a, b, …z } = myObj;
console.log(a); // 1
console.log(b); // 3
console.log(z); // {c: 5, d: 8}

// using the spread syntax we cloned our Object
let clone = { …myObj };
console.log(clone);
// {a: 1, b: 3, c: 5, d: 8}
myObj.e = 15;
console.log(clone)
// {a: 1, b: 3, c: 5, d: 8}
console.log(myObj)
// {a: 1, b: 3, c: 5, d: 8, e: 15}

ES8 — Asynchronous Iteration

This update enables you to use await to declare asynchronous loops if the data comes from an asynchronous source. We use the for-await-of to convert the iterables to a Promise.

Get Sara’s stories in your inbox

Join Medium for free to get updates from this writer.

The GitHub documentation explains that “an async iterator is much like an iterator, except that its next() method returns a promise for a { value, done } pair.”

const iterables = [1,2,3];

async function test() {
for await (const value of iterables) {
console.log(value);
}
}
test();
// 1
// 2
// 3

ES8 — Other updates from ES8:

  • String Padding
  • Shared memory and atomics
  • Object.getOwnPropertyDescriptors( )
  • Trailing commas in function parameter lists and calls

--

--

Sara
Sara

Written by Sara

Front End Developer. Always learning.