When you use console.log
to display information that cannot be directly printed, the respective toString
method is invoked to still provide a summary of the most important details about the function.
As explained on MDN, the toString method generates a string representation of the object in the form of a function declaration, including the function keyword, argument list, curly braces, and the source code of the function body.
This approach allows developers to debug without needing to access the internal details by easily viewing the function's source either in devtools or an editor.
In my comparison using various browsers' dev tools:
console.log(function(a, b) { return a + b; });
The outputs were different across browsers:
While I couldn't test this in IE due to being on a Mac, the variation in outputs highlights how developer preferences dictate which browser to use as the console logging behavior is not consistent cross-browser.