Why do we have to write function() {/*call some other function*/} or () => {} inside .then() in promise?
Let's say for example that we have one promise
someFn = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve("Resolved");
}, 2000);
})
}
And we also have random function
anotherFn = () => {
console.log("in time");
}
To chain those functions we will use .then()
someFn().then(success => console.log(success)).then(() => anotherFn());
My question is, why is anotherFn() executed immediately if I write it like this .then(anotherFn()) and it waits with execution if it has () => {}?
As far as I know, the first argument that .then() takes is onFulfilled which is a function, and anotherFn() is also a function.