console.log javascript [Function]


Question

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.

1
86
2/27/2012 6:20:03 AM

Accepted Answer

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);
124
1/4/2014 6:11:10 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon