Are there differences between .then(functionReference) and .then(function(value){return functionReference(value)})?

It is possible to create a case where there is a difference when no argument is passed, but it is a stretch and generally you should pass f and not function(x) { return f(x); } or x => f(x) because it is cleaner.

Here is an example causing a difference, the rationale is that functions that takes parameters can cause side effects with those parameters:

function f() {
   if(arguments.length === 0) console.log("win");
   else console.log("Hello World");
}
const delay = ms => new Promise(r => setTimeout(r, ms)); // just a delay
delay(500).then(f); // logs "Hello World";
delay(500).then(() => f()) // logs "win"

Leave a Comment