Javascript Promise Basic Things
Mahin Tazuar
Posted on January 17, 2022
Promise-
Sometimes we needed asynchronous javascript behavior. suppose when we are want to get data from the internet server but we know if we want to get some data, it needs some time but javascript working synchronously it gives an error when it does not find any things.
promise just help to javascript asynchronous behavior like if have any true value it's going for resolve otherwise its return rejects call back function.I need to catch the resolved value you need to use then and if need to catch the reject message, need to use the catch function with an arrow function as a parameter.
// promise syntext
let x =10;
const promises = new Promise((resolve, reject) => {
if (x ==10) {
resolve('workin');
}
else {
reject('working');
}
});
promises.then((w) => {
console.log(w);
});
đź’– đź’Ş đź™… đźš©
Mahin Tazuar
Posted on January 17, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
javascript Mastering Design Patterns in JavaScript: Part 5 — The Decorator Pattern
November 5, 2024