What is console.log in jQuery?

JavascriptJquery

Javascript Problem Overview


What is console.log? What is it used for in jQuery?

Javascript Solutions


Solution 1 - Javascript

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 - Javascript

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 - Javascript

it will print log messages in your developer console (firebug/webkit dev tools/ie dev tools)

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
Questionuser398993View Question on Stackoverflow
Solution 1 - JavascriptzzzzBovView Answer on Stackoverflow
Solution 2 - JavascriptRichView Answer on Stackoverflow
Solution 3 - JavascriptMatt BriggsView Answer on Stackoverflow