What is console.log in jQuery? [duplicate]
What is console.log
? What is it used for in jQuery?
Solution 1:
jQuery and console.log
are unrelated entities, although useful when used together.
If you use a browser's built-in dev tools, console.log
will log information about the object being passed to the log
function.
If the console is not active, logging will not work, and may break your script. Be certain to check that the console exists before logging:
if (window.console) console.log('foo');
The shortcut form of this might be seen instead:
window.console&&console.log('foo');
There are other useful debugging functions as well, such as debug
, dir
and error
. Firebug's wiki lists the available functions in the console api.
Solution 2:
It has nothing to do with jQuery, it's just a handy js method built into modern browsers.
Think of it as a handy alternative to debugging via window.alert()
Solution 3:
it will print log messages in your developer console (firebug/webkit dev tools/ie dev tools)