life is too short for a diary




Daily Logs for May 24, 2026

Tags: letters javascript async promises

Author
Written by: Tushar Sharma
Featured image for Daily Logs for May 24, 2026

Dear Vishi, dear logs for today.

JavaScript Promises vs Async/Await

In JavaScript, asynchronous operations often return a Promise. A Promise represents a value that may be available now, later, or never if an error occurs.

Let's look at a method that makes a GET request. The function is asynchronous and returns a Promise, which is either resolved with the server response or rejected if an error occurs.

const data = await fetchData(
  url,
  params,
  options
).catch(() => {
  showError('Request failed')
})

The await keyword pauses the execution of the current async function until the Promise returned by fetchData is settled. This allows the code to wait for the result before continuing, making asynchronous code easier to read compared to traditional Promise chaining.

Musing

The older you get, the more you relaize that luck is nothing but more exposure.

If you just sit in the same chair, same routine, talking to same people…nothing new happens.

You have to touch the world to win:


comments powered by Disqus