w3schoon Posted February 13, 2013 Share Posted February 13, 2013 Nice be with you everyone! My question is: What is the usage of console.log in jQuery? Thank you. Link to comment Share on other sites More sharing options...
Ingolme Posted February 13, 2013 Share Posted February 13, 2013 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 More sharing options...
callumacrae Posted February 13, 2013 Share Posted February 13, 2013 Note that you should only use it for debugging, you shouldn't use it in production code. It doesn't exist in a couple browsers, and so using it will throw an error and stop your code from running. Link to comment Share on other sites More sharing options...
thescientist Posted February 13, 2013 Share Posted February 13, 2013 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 More sharing options...
Ingolme Posted February 13, 2013 Share Posted February 13, 2013 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 More sharing options...
w3schoon Posted February 14, 2013 Author Share Posted February 14, 2013 (edited) 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! Edited February 14, 2013 by w3schoon Link to comment Share on other sites More sharing options...
Ingolme Posted February 14, 2013 Share Posted February 14, 2013 You can open developer tools by pressing F12. There's a "Console" tab on them where the messages will appear. Link to comment Share on other sites More sharing options...
w3schoon Posted February 14, 2013 Author Share Posted February 14, 2013 Thank you very much! I really want to learned how to debug javascript using console.log, but my problem is where I should start?Any link of good console.log Introduction? Link to comment Share on other sites More sharing options...
thescientist Posted February 14, 2013 Share Posted February 14, 2013 (edited) 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 February 14, 2013 by thescientist Link to comment Share on other sites More sharing options...
justsomeguy Posted February 14, 2013 Share Posted February 14, 2013 You can also use console.info, console.error, console.warn, console.debug etc to write other kinds of messages. https://developers.google.com/chrome-developer-tools/docs/console Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now