Book Image

Advanced JavaScript

By : Zachary Shute
Book Image

Advanced JavaScript

By: Zachary Shute

Overview of this book

If you are looking for a programming language to develop flexible and efficient applications, JavaScript is an obvious choice. Advanced JavaScript is a hands-on guide that takes you through JavaScript and its many features, one step at a time. You'll begin by learning how to use the new JavaScript syntax in ES6, and then work through the many other features that modern JavaScript has to offer. As you progress through the chapters, you’ll use asynchronous programming with callbacks and promises, handle browser events, and perform Document Object Model (DOM) manipulation. You'll also explore various methods of testing JavaScript projects. In the concluding chapters, you'll discover functional programming and learn to use it to build your apps. With this book as your guide, you'll also be able to develop APIs using Node.js and Express, create front-ends using React/Redux, and build mobile apps using React/Expo. By the end of Advanced JavaScript, you will have explored the features and benefits of JavaScript to build small applications.
Table of Contents (9 chapters)


Async/await is a new syntax form added to simplify code that uses promises. Async/await introduces two new keywords: async and await. Async is added to function declarations and await is used inside an async function. It is surprisingly easy to understand and use. In its simplest form, async/await allows us to write promise-based asynchronous code that looks almost identical to the synchronous code that does the same task. We will use async/await to simplify code using promises and make it even easier to read and understand.

Async/Await Syntax

The async keyword is added to function declarations; it must precede the function keyword. An async function declaration defines an asynchronous function. An example declaration of an async function is shown in the following snippet:

async function asyncExample( /* arguments */  ){ /* do work */ }

Snippet 2.34: Implementing promises

An async function implicitly returns a promise, no matter what the return value is specified to be. If the return...