Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is console.log in jQuery? [duplicate]

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

like image 511
user398993 Avatar asked Jul 24 '10 05:07

user398993


People also ask

What is console log in jQuery?

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.

What does console log () do?

The console. log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user.

Is return and console log same?

Answer 505b42d70d4e860002000188console. log() is a function used to print information to the console. return on the other hand is a call to pass some value back up to where the call was made.

What is use of console log in JavaScript?

The console. log() method outputs a message to the web console. The message may be a single string (with optional substitution values), or it may be any one or more JavaScript objects. Note: This feature is available in Web Workers.


3 Answers

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.

like image 55
zzzzBov Avatar answered Oct 16 '22 11:10

zzzzBov


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

like image 39
Rich Avatar answered Oct 16 '22 10:10

Rich


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

like image 8
Matt Briggs Avatar answered Oct 16 '22 10:10

Matt Briggs