How to improve your asynchronous Javascript code with async and await

How to improve your asynchronous Javascript code with async and await

If you’ve had the chance to observe modern Javascript code — chance are high you have seen the async and await syntax somewhere.

Async/await is arguably one of the best-received new additions to the language. Async/await makes asynchronous code appear and behave like synchronous code. Async/await are promise-based.

Before we jump into async/await, we must understand what are promises and the role they play.

Promises

The Promise object represents the eventual completion (or failure) of an asynchronous operation, and its resulting value.”)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

Why do we need asynchronous code, anyway?

How to use destructuring and arrow functions to improve your JavaScript code

Without further ado, here are some everyday “tricks” to make your Javascript code much more readable.

Destructuring

Take this (intentionally) deeply nested object. Reading the age of a mammal would lead us to a very verbose and repetitive code.

Instead of doing that, we can use shorten our code by a huge margin with object destructing.

Object destructuring

Destructing bear and deer

Much better and less verbose. Note that we’re using constants since we don’t want to change the age. But think about it: age is not a constant… once per year in fact the age does increment.

All you need to know about the Web Audio API

Did you know Javascript has a constantly evolving high-level API for processing and synthesizing audio? How cool is that!

The goal of the audio API is to replicate features found in desktop audio production applications. Some of the most prominent features are mixing, processing, filtering, etc.

The web audio API has a lot of potential and can do awesome stuff. But first — how well is the API supported across the board?

green across all boards

Cool, worth digging into. 👍

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×