Jump to content

Usage of console.log in jQuery


w3schoon
 Share

Recommended Posts

It's not jQuery, it's available in Javascript. It leaves a message in the browser's Javascript console. When you're debugging it's far more useful than alert() statements to show the data you're testing.

Link to comment
Share on other sites

I've been able to get console.log to work (or at lease not throw errors) in all version of IE > 7, Opera, Chrome, FF, and Safari. You just need to define the object/method ahead of time in your JS.

Link to comment
Share on other sites

I'm quite sure jQuery does actually use console.log() to send messages to developers that are using it. If you're building a Javascript library or application you might want to keep console.log() statements. To make sure your program will work in browsers that don't support it you just declare an empty method if it doesn't already exist.

if(!console) {    console = {};    console.log = function() {};}

Link to comment
Share on other sites

Wow! That is amazing, I usually use alert() statements for debugging and I didn't know that console.log is more useful than alert() statements! May I know where I can find "browser's Javascript console" (if my browser is Google Chrome)? Thanks a lot! :D

Edited by w3schoon
Link to comment
Share on other sites

what do you need to know? Just start logging stuff and you'll see. For example, logging arrays and objects will allow you expand/collapse their indexes/properties right in the console. Extrememely useful. Also, you can use it just like alert statements to leave trace logging to follow your code as it executes.

Edited by thescientist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...