Recently I stumbled upon the Promise.then
example on MDN just before this article https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises#nesting
The example uses this:
.then((url) =>
fetch(url)
.then((res) => res.json())
.then((data) => {
listOfIngredients.push(data);
}), // Note this comma here
)
In simple terms this is equivalent to the following:
.then(successFunc,);
To my surprise, this actually doesn’t throw any error. Following works, but why?
const speakPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("success");
}, 500);
});
speakPromise.then(function (data) {
console.log(data, " End code");
}, ); // Note the trailing comma here