Everyone. Console.log works for everyone. Back in my for loops post, I said I would explain why I said to use console.log(), instead of alert(), and here it is!
So with this in mind, console.log was a complete mystery to me. After all, it didn’t actually do anything, did it? I mean, on Codecademy it shows up in that one console-looking part of the screen, but I tried it on a website and it didn’t do anything.
You can even see me here on Twitter, asking the question, “just what exactly is this thing good for anyway?”
Hahaha, wasn’t I cute?
Yes, it is true that console.log doesn’t put anything on the page. What I didn’t realize though was how powerful it can be for debugging. (Yes, it’s true, I do have to debug my code.)
If you think back to my for loops post, I used console.log through the loop to expose the multiplier variable. (If you can’t quite remember the code, you can see it here on JSFiddle.)
If you don’t remember, or haven’t tried it, go ahead and open up that link above in a new tab, and open up dev tools. (Right click on the screen, and look for ‘Inspect Element’ in that menu.)
Navigate over to the console. (In the menu, on the right, there should be a ‘console’ option.)
Now go ahead and run the function, and watch what happens….
There are loads of good uses for console.log, this is just one example. I hope it helps you understand why you might want to use something like this while developing. Just because it doesn’t appear to do anything to your site doesn’t mean it’s without value.
His console.log post details a lot of other cool things you can do with console.log in Google Dev tools. Definitely check it out!
Questions? Tweet me!