what's a promise code example

Example 1: what is a promise

// Promise is a special type of object that helps you work with asynchronous operations.
// Many functions will return a promise to you in situations where the value cannot be retrieved immediately.

const userCount = getUserCount();
console.log(userCount); // Promise {<pending>}

// In this case, getUserCount is the function that returns a Promise. If we try to immediately display the value of the userCount variable, we get something like Promise {<pending>}.
// This will happen because there is no data yet and we need to wait for it.

Example 2: what is promise in javascript

Promises make async javascript easier as they are easy to use and write than callbacks. Basically , promise is just an object , that gives us either success of async opertion or failue of async operations

Tags:

Misc Example