console.log javascript [Function]

JavascriptFunctionnode.jsConsole

Javascript Problem Overview


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.

Javascript Solutions


Solution 1 - Javascript

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHarryView Question on Stackoverflow
Solution 1 - JavascriptPaulView Answer on Stackoverflow