133

I'm trying to log a function in javascript:

console.log(callback)
>>[Function]

I want to see what the function is. Can I do that? Thanks.

Harry
  • 52,711
  • 71
  • 177
  • 261

1 Answers1

188

If it's a user defined function you can use:

console.log(callback.toString());

Otherwise you'll just get something like [native code] since built in functions are not written in JavaScript.

Example:

function x(){}

// Prints "function x(){}"
(function(callback){ console.log(callback.toString()); })(x);
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Paul
  • 139,544
  • 27
  • 275
  • 264