Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

new promise function

const myPromise = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve('foo');
  }, 300);
});

myPromise
  .then(handleResolvedA, handleRejectedA)
  .then(handleResolvedB, handleRejectedB)
  .then(handleResolvedC, handleRejectedC);
Comment

nodejs promise then example

p.then(onFulfilled, onRejected);

p.then(function(value) {
   //  run
  }, function(reason) {
  // fail
});
Comment

Creating a promise

JS
copy
let done = true

const isItDoneYet = new Promise((resolve, reject) => {
  if (done) {
    const workDone = 'Here is the thing I built'
    resolve(workDone)
  } else {
    const why = 'Still working on something else'
    reject(why)
  }
})
Comment

Making promises

new Promise((resolve, reject) => {
  if (ok) { resolve(result) }
  else { reject(error) }
})
 
Comment

Using Then To Create A Promise In JavaScript

async function abc()
{
Promise.resolve("hello world").then(function(value)
{
	console.log(value);
    }
Comment

javascript Program with a Promise

const count = true;

let countValue = new Promise(function (resolve, reject) {
    if (count) {
        resolve("There is a count value.");
    } else {
        reject("There is no count value");
    }
});

console.log(countValue);
Comment

Create A Promise In JavaScript

async function abc() 
{ 	
	const myPromise = new Promise(function(resolve, reject) {
   resolve("hello world");
});
let y= await myPromise;
console.log(y);
/*"hello world*/
	}
Comment

Create A Promise And Then Return It


let fetchSent =	fetch("/test", {method:"POST", body: JSON.stringify({name:"NAME NAME NAME"}), headers: {'Content-type': 'application/json; charset=UTF-8'}});
const p1 = new Promise((resolve, reject) => {
  resolve(fetchSent);
  // or
  // reject(new Error("Error!"));
})
	 

 return p1;
/*console.log(p1) will yield the fetch promise that was sent to you*/
Comment

javascript Create a Promise

let promise = new Promise(function(resolve, reject){
     //do something
});
Comment

making promises in js

getData()
    .then(data => console.log(data))
    .catch(error => console.log(error));
Comment

PREVIOUS NEXT
Code Example
Javascript :: next js redirect if not logged in 
Javascript :: react useEffect prevent first time 
Javascript :: mongoose get id after save 
Javascript :: Using the reverse method to Reverse an Array 
Javascript :: mongoose remove data 
Javascript :: validação de email email@email.com 
Javascript :: discord.js dm all members 
Javascript :: flatten json python 
Javascript :: https express 
Javascript :: array some 
Javascript :: onclick hold react 
Javascript :: react native swiper 
Javascript :: tailwind container class size 
Javascript :: assign random colors react chartjs 
Javascript :: export module in es6 
Javascript :: else statement 
Javascript :: what is a promise 
Javascript :: date string to date in js 
Javascript :: how to practice javascript 
Javascript :: elapsed time function() {math javascript 
Javascript :: get smallest value in array js 
Javascript :: how to print in java script 
Javascript :: async map js 
Javascript :: get current tab from chrome extension developer 
Javascript :: how to delete object properties in javascript 
Javascript :: send data using fetch 
Javascript :: javasciprt set cookie 
Javascript :: JavaScript super() keyword 
Javascript :: function for flatten an array 
Javascript :: check empty object javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =