console.log javascript [Function]

Harry picture Harry · Feb 27, 2012 · Viewed 80.7k times · Source

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.

Answer

Paul picture Paul · Feb 27, 2012

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);