JSFiddle - React, Tailwind, and code Playground
by Allie Yu
JavaScript
/* let val = 'bar';
const func = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(val);
},0)
})
}
val = 'wut';
const promise1 = func();
val = 'wiz';
promise1.then((value) => {
console.log(value + 'baz');
}).catch((err) => {
console.log(err+'bat');
});
console.log('foo') */
const func = val => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(val);
},0)
})
}
func('foo')
.then((result) => 'bar', (error) => 'wut')
.then((result) => console.log(result))
func('baz')
.then((result) => {throw new Error(result)})
.then((result) => 'bat', (error)=> 'beep')
.then((result) => console.log(result))