# My JavaScript Learning Journey - Week 9: Promises, API Calls, JavaScript Operators & Modules

Every week of my JavaScript learning journey introduces me to something new. Some concepts take time to understand, while others become clearer when I practise them with small examples.

During Week 9, I explored Callback Hell, Promises, API calls, Optional Chaining, Nullish Coalescing and JavaScript Modules.

I also started working on a new mini project called CountryExplorer, which gave me an opportunity to move beyond learning individual concepts and start building something practical.

In this article, I will share what I learned from Day 46 to Day 50, along with some simple examples that helped me understand these concepts.

Let's get started!

## Day 46: Understanding Callback Hell and Promises

On Day 46, I learned about Callback Hell in JavaScript and why it can make code difficult to read and maintain.

Before understanding Callback Hell, I wanted to understand why callbacks are used in JavaScript.

### What is a Callback?

A callback is a function passed as an argument to another function. It can be executed later, depending on how the receiving function is written.

Here is a simple example:

```javascript
function greet(name, callback) {
  console.log(`Hello, ${name}!`);

  callback();
}

function sayWelcome() {
  console.log("Welcome to my website!");
}

greet("Dharmapada", sayWelcome);
```

Output:

```plaintext
Hello, Dharmapada!
Welcome to my website!
```

Here, sayWelcome is passed as an argument to the greet() function and executed inside it.

Callbacks are useful in JavaScript, especially when working with asynchronous operations.

### What is Callback Hell?

Callback Hell happens when multiple callbacks are nested inside one another, creating deeply indented and difficult-to-manage code.

Let is understand this with a simple example:

```javascript
function firstTask(callback) {
  console.log("First task completed");

  callback();
}

function secondTask(callback) {
  console.log("Second task completed");

  callback();
}

function thirdTask() {
  console.log("Third task completed");
}

firstTask(() => {
  secondTask(() => {
    thirdTask();
  });
});
```
