ECMAScript ES8 and Beyond

I’m writing this post with a lot of excitement. I’ve decided to play around with new ECMAScript proposals since ES6 has already been out there for quite a long time and ES7 comes with just two new features (which are the exponentiation operator (**) and the Array.prototype.includes() function).

The above (especially ES6) gave us huge improvements in code readability. Personally, I love syntax sugar, so things that are coming to JavaScript with ES8+ make me really happy.

Unveiling ES-next Features with Presets

Thanks to Babel’s stage-0 preset we can already use things that will be included in ES8 or later specifications, or even those that are at just proposals. Babel offers us quite a few presets — depending of how far we want to go in ES-next — and we can choose the preset that we feel like trying out. Here’s the list of currently available presets:

  • stage-0 — Strawman: just an idea, possible Babel plugin.
  • stage-1 — Proposal: this is worth working on.
  • stage-2 — Draft: initial spec.
  • stage-3 — Candidate: complete spec and initial browser implementations.
  • stage-4 — Finished: will be added to the next yearly release.

I’ll present some features from each preset — to hopefully get you to use this amazing transpiler and boost your code with some syntax improvements.

Diving into stage-3: The async-await marvel

I’ll start with my favorite feature of the stage-3 preset which is the transform-async-to-generator plugin. It adds two new keywords to our code, namely async and await. I’m using them constantly in my backend applications.

Here is the basic syntax:

It works just like generators — the await keyword makes our application wait until our promise is resolved. It’s very useful for API or DB calls. Here’s a small real-life example:

And that’s all — the result of our promise is assigned to ‘user’. The power of this transform is that it doesn’t use regenerator or any other runtime but desugars to native generators that are already supported on Node 6.x and other environments. You can get rid of a pyramid of callbacks in .then() functions, and make your code clean and readable.

Revolutionizing objects with stage-2: The object rest-spread plugin

Our next preset is stage-2 — it comes with one plugin only, but trust me — it’s a good one. Plugin transform-object-rest-spread is a game-changer. Using it, you can rest and spread object properties and reduce the amount of code you have to write in this specific use case. Here’s an example:

Amazing, isn’t it? If you haven’t been using it yet — now it’s about time you start. The deeper we go into the new ECMAScript proposals, the more amazing features we can use.

Stage-1 wonders: A glimpse at transform-class-properties

Proposal preset stage-1 used to give us the transform-decorators plugin — but since there is a pending proposal update — it has been temporarily disabled. But worry not — we will look at another amazing feature, the transform-class-properties plugin. It’s very useful with react (DOM or native) — technologies. Now you can use the following syntax to bind a property to a class:

You can use it to define state or check propTypes in react classes as follows:

Stage-0 marvels: Simplifying code with the bind operator

Last but not least, the stage-0 preset comes with my favourite ES-nextproposal — the bind operator (::). If you are tired of using .call() .bind()and .apply() functions, this syntax is just for you. Babel gives us an example below:

But i think you’ll see it all better in this example. Here is the code written in ES5:

And how we can make it simpler using the new syntax. Take a look:

Basically, those are the most important ES-next tools you can use at the moment. But I’m also curious about what’s coming to JavaScript in the next few years. One of the most interesting proposals is async iteration. AsyncIterator interface should be the same as the Iterator interface, except for the fact that each iteration method would return a promise. You could iterate like this:

This iterator comes with a variation of the for-of iteration statement, so you can iterate through your promises with syntax like this:

Peeking into the future

As you can see, all of these features give JavaScript a bright future, and can make the language even more powerful than it is now. You should of course visit Babel.js docs and customize your presets to match your needs and desires. There are still many more things to come. There are many GitHub repositories with new proposals that you can rate and contribute to. Any contribution, of course, will be of great value to the community.

Insights

Learn more about JavaScript

cover

Jun 26Article

React Native Legal: CLI & Programmatic API - Unified Tooling for License Attributions

Discover React Native Legal, the first unified solution for managing open-source license attributions. Automatically handle both JS & native dependencies in any project via a powerful CLI and programmatic API.

cover

Dec 14Article

ReasonML for JS developers

If you are a JavaScript developer and want to learn a new functional language, this article is a must-read for you. Check it out!

cover

Jun 13Article

Manage Async Code Like a PRO With RxJS

Discover the Saviour for async code management in React with our blog post.

cover

Dec 12Article

JavaScript Hacking 101

In this article we takie a look at how things work in JavaScript under the hood.

cover

Mar 19Tutorial

The Hard Way vs. The React Native AI SDK Way: Stop Writing Custom Modules for Every Model

Learn how React Native AI uses a unified provider model to switch between cloud and on-device LLMs without rewriting application logic, enabling reliable AI experiences online and offline.

cover

Mar 12Tutorial

Build Smarter Apps: Tool Calling & AI Orchestration Explained

Learn how on-device models in React Native can call tools, interact with external APIs, and return structured outputs you can use directly in application logic.

cover

Mar 5Tutorial

MLC LLM + React Native: On-Device AI Without the Pain

Learn how to run third-party on-device LLMs in React Native using MLC LLM. Choose your models, run them efficiently across platforms, and keep a unified JavaScript API with React Native AI.

cover

Feb 24Tutorial

Intelligent Fallbacks with Apple Intelligence in React Native

Learn how to use Apple’s built-in Foundation Models in React Native apps, reduce memory usage, and enable fast, fully on-device AI with React Native AI Apple.

cover

Feb 10Tutorial

What Is the React Native AI SDK? A Complete Intro & Quickstart

Learn why on-device AI matters for React Native apps, how local LLMs behave offline, and what problems React Native AI is designed to solve from day one.

cover

Jan 29Tutorial

Implementing an Android TurboModule with Kotlin

Learn how to implement a React Native TurboModule on Android, from the TypeScript spec and Codegen to the Kotlin implementation and package registration.

cover

Jan 19Tutorial

Working with Different Threads in Swift TurboModules

Learn how JavaScript, native module, background, and main threads interact in React Native TurboModules, and how to use GCD queues to run async work safely in Swift.

cover

Jan 9Tutorial

How to Add Type-Safe Constants to Swift TurboModules

Learn how to expose typed, immutable constants from a Swift TurboModule using Codegen, and get full end-to-end type safety between native and JavaScript.

cover

Dec 30Tutorial

Adding Event Emitters to Your TurboModule in Swift

Learn how to emit native events from a Swift TurboModule and subscribe to them in JavaScript, including proper memory management and Codegen integration.

cover

Dec 22Tutorial

Writing Your First TurboModule in Swift

Learn how to build a fully working TurboModule in Swift, integrate it with Codegen, and bridge it through Objective‑C inside an Expo app.