A promise is an object used as a placeholder for a value, which might be available as a result of asynchronous operations such as a response from an HTTP request.

When we make an asynchronous call, it immediately returns a promise object to register callbacks that will run when the asynchronous call succeeds or an error occurs.

Let’s first look at an example of callbacks and then see how we can convert it into a promise.

function sayHello() {
console.log("Hello");
}
setTimeout(sayHello, 2000);

Let’s consider the above example. Here, setTimeout might be the asynchronous task that takes 2 seconds for…


Let's first discuss how variables declared, withvar and let are different.

Both let and var are used to declare variables, that can be optionally initialized at the time of declaration.

As per MDN:

The var statement declares a function-scoped or globally-scoped variable, optionally initializing it to a value.

The let statement declares a block-scoped local variable, optionally initializing it to a value.

But there are considerable differences in terms of their creation and their usage.

Differences at the time of the creation and execution

Parsing a JavaScript program is a two-step process.

Two-step process for variables with var

  1. Creation Step — This step looks for each variable and function…

Nandan Pandey

Sr. JavaScript Developer at GlobalLogic, React, Nextjs, GraphQl, Serverless, JamStack

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store