0

Why does the following code runs:

someExpression.then((result)=>{
    console.log(util.inspect(result,{depth:null}));
    return result;
}))

and when this function has a name it doesn't:

function print(result) {
    console.log(util.inspect(result,{depth:null}));
    return result;
}

someExpression.then(print(result)))

with error:

ReferenceError: result is not defined

Amit
  • 45,440
  • 9
  • 78
  • 110
arisalexis
  • 2,079
  • 2
  • 21
  • 42

1 Answers1

3

You're not passing a function in your second example. You're executing a function and passing its result.

The proper way to do this would be:

someExpression.then(print)
William Barbosa
  • 4,936
  • 2
  • 19
  • 37