Please help me understanding js promises

Hi friends how are you. I need help i’m confuse understanding js promises this is my code.
const savePromise = fetch(url).then(response => console.log(response)).catch(err => console.log(err)) console.log(savePromise); // promise pending

i want to know that which promise stored in savePromise variable because then return promise and catch also return promise so catch promise is stored in savedPromise variable ? i run code in debugger so i know that first time code also goes to catch which means catch return promise.

the Promise returned by the catch method is stored in savePromise

what happened in this situation
Is promise return by catch method store in coffee variable ?
One thing i want also clear, Is then method immediately return promise like setTimeout return value for clearing timeout ?

try running this for example:

    const savedPromise = fetch(url).then(response => {throw "123"}).catch(err => {throw "124"});
    savedPromise.catch(err => console.log("I got error number " + err))



I’m so thankful to you the puzzle is solved.

1 Like