The .catch() method for handling rejection - Cheat Sheet Code Error

I have spotted an error in the code example for ‘The .catch() method for handling rejection’, on the Promises cheat sheet page in the the Learn Intermediate JavaScript.

const promise = new Promise((resolve, reject) => { setTimeout(() => { reject(Error('Promise Rejected Unconditionally.')); }, 1000); }); promise.then((res) => { console.log(value); }); promise.catch((err) => { alert(err); });

The first .then() handler returns a value of ‘value’ instead of ‘res’. ‘value’ is not defined and will not return anything. This is somewhat of a moot point as the promise in this example unconditionally rejects, however it nonetheless may cause confusion and should be corrected to the following code:

const promise = new Promise((resolve, reject) => { setTimeout(() => { reject(Error('Promise Rejected Unconditionally.')); }, 1000); }); promise.then((res) => { console.log(res); }); promise.catch((err) => { alert(err); });