Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Introducing JavaScript The JavaScript Console

Do you leave console.log in your final code?

So I might be getting ahead of myself and this may be covered in later videos, but I'm just curios do you leave console.log in your final code when you publish a site? Or is it just to use while debugging and then should be removed before your code/site is published?

3 Answers

You'll probably want to remove the console.log calls before going live with a site. They wouldn't hinder the site in any way, but it's the equivalent of cleaning up after work.

If users were to see them on accident, they might be confused by them. Other devs would be surprised you hadn't removed them.

The thing is, as you gain more experience with JavaScript, you'll be using console.log calls less often and they'll be easier to remove.

The only time I leave them in is if I want to make some sort of an easter egg for users. But then the message displayed is intentional and not debug info.

László Győri
László Győri
82,430 Points

You should definitely remove them, because legacy browsers like IE8 and 9 don't support it and it will cause an error, which can affect other pieces of script.

The previous statement is not entirely correct, the console object is supported, but only when the dev tools window is open. This obviously doesn't affect regular users though. Also it can be confusing to hunt errors like this down, because once you open dev tools the error, by design, disappears.

Thanks for the answers guys! Very helpful to know.