---
title: "Rethinking Async in JavaScript"
description: "Evolution from callbacks to promises to async/await. Practical notes and code examples on Rethinking Async in JavaScript by."
url: "https://h3manth.com/scribe/rethinking-async-in-javascript/"
canonical_url: "https://h3manth.com/scribe/rethinking-async-in-javascript/"
markdown_url: "https://h3manth.com/scribe/blog/rethinking-async-in-javascript.md"
publishDate: "2016-12-10T00:00:00.000Z"
author: "Hemanth HM"
category: "javascript"
tags: ["javascript","async"]
word_count: 89
reading_time_minutes: 1
x_markdown_tokens: 256
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Rethinking Async in JavaScript

> Evolution from callbacks to promises to async/await. Practical notes and code examples on Rethinking Async in JavaScript by.

A dramatic dialogue about async evolution in JavaScript:

## The Callback Era

```javascript
function read(filename, callback) {
  fs.readFile(filename, 'utf8', function(err, res) {
    if (err) return callback(err);
    callback(null, res);
  });
}
```

**Avoiding Callback Hell:**
- Name your functions
- Keep code shallow
- Modularize
- Bind `this`

## The Promise Era

```javascript
promise.then(result => {
  console.log(result);
}).catch(err => {
  console.log(err);
});

## The Async/Await Era
javascript
async function getData() {
  const result = await fetch(url);
  return result.json();
}
```

From callbacks to Promises to async/await - the journey continues!
