1 minute read

With the soon to be released (June-ish) of ECMAScript 2022 I thought it would be a nice idea to have a look at some interesting features en-route.

More Privacy

With classes being around since ES6 coding JS in a traditional OOP style became a lot more straight forward. One thing was missing and that was the ability to set the accessibility of properties and methods in your classes.

class Person {
  name = "Peter Maddox";
  #address = "123 Faker, Street";
  
  #setAddress(address) {
    this.address = address;
  }

  #getAddress() {
    return this.address;
  }
}

const person = new Person();
person.#setAddress('456 Crown Rd.'); // OK
person.#getAddress(); // OK
person.address; // ERROR

Top-Level Await

Writing async code in JS has always furrowed the strongest of brows but instead of writing something like this for example.

(async () => {
  const data = await fetch('...');
})();

We will soon be able to do something like this.

const data = await fetch('...');

No need for a wrapping immediately invoking function!

Arrays Made Slightly Easier

With the new at() method we can access iterables from the end, woohoo! Instead of this:

const arr = [1,2,3,4,5,6,7,8,9,10]
arr[arr.length - 3] // 8

We will soon be able to do this magic!

const arr = [1,2,3,4,5,6,7,8,9,10]
arr.at(-3) // 8

If you’re thirsty for more why not check this out - New in ECMAScript 2022.