DEV Community

Cover image for Why using just console.log in 2023 is a big no-no 🚀

Why using just console.log in 2023 is a big no-no 🚀

Al - Naucode on December 07, 2022

Here are 5 must-know console object methods and tricks! Are you still using console.log for all your JavaScript debugging needs in 2023? It's tim...
Collapse
 
leob profile image
leob

Great article, useful to know, but console.log isn't a "big no-no" at all, it just depends on how you use it - most of the time I just use it as a temporary statement to debug something, and when I'm done I delete it from my code :)

Collapse
 
leober_ramos33 profile image
Leober Ramos

Marketing bro, you have to know how to sell your post. Also, the man tries to talk about people who only use "console.log" and don't know the other methods that the JavaScript "console" object has.

But yes, console.log is also a good method and can be used together with these others, since although the others are good, for example to print any type of data on the console (boolean, object, string, etc.) it's better to use console.log.

Collapse
 
leob profile image
leob

Yeah you're right, the "big no-no" makes for a catchy title, it draws attention ... well yes, I purely insert console.log's to dump a piece of data in order to debug an issue, once I've solved it my console.log statement will be promptly deleted from the code ... anyway, these new console methods are definitely cool!

Thread Thread
 
naucode profile image
Al - Naucode

Yeah, most people most of the time (even myself) will continue using the console.log. It is not a bad thing. This is just a way to raise some attention in other methods that sometimes we can use. I like to use for example the time and assert ones.

Thread Thread
 
leob profile image
leob

I've used the time one as well, it's great (to time a piece of 'synchronous' JS code)

Collapse
 
radualexandrub profile image
Radu-Alexandru B

Yes logging is very okay.
However in my most scenarios I just use console.debug() and console.error() instead (so most of the logging will be invisible to the end user -> "verbose" mode should be enabled in order to see the debug logs).

Here's an example of how I use logging most of the times:

  onBuildUrl(urlNewForm: NgForm) {
    const methodName = 'onBuildUrl()';

    console.debug(
      `${methodName} urlNewForm ${JSON.stringify(urlNewForm.value)}`
    );
    try {
      this.urlNew = new URL(urlNewForm.value.href);
      console.debug(`${methodName} New URL ${this.urlNew}`);
    } catch (error) {
      console.error(
        `${methodName} ${urlNewForm.value.href} is not a valid URL - ${error}`
      );
    }
  }
Enter fullscreen mode Exit fullscreen mode
Collapse
 
leob profile image
leob

Yeah that could be very useful, especially if you could make the logs available in a production app (that would require some sort of periodic Ajax call to sync the logs to a backend) ... I assume that console.debug has negligible overhead if it's disabled/non-verbose?

Thread Thread
 
radualexandrub profile image
Radu-Alexandru B • Edited

Yes, that's right. In production we should not only use console.log/debug/anything as they're only accessible on end-user's browser... instead, we should (also) use a proper Node.js logging library (that could provide full timestamps as well), such as the ones mentioned on this StackOverflow thread. (Also keep in mind that some apps should never use console.logging in the browser, as sensitive information could be shown/accessible by end user)

Also on end-user's browser, console.debug are still written on the console (eg. DevTools), but they are just not visible if "Verbose" is not checked from options.

Collapse
 
walze profile image
wallace fares

Yea I was gonna say the same thing, other than the cringy click baity title, the article is good as well

Collapse
 
brense profile image
Rense Bakker

Console assert is awesome! Doesn't polute your console when everything is running fine and gives you enough data to debug when something goes wrong

Collapse
 
naucode profile image
Al - Naucode

Yeah! It is a really good method

Collapse
 
liftoffstudios profile image
Liftoff Studios

Or better yet, Don't use console methods 😬, use the inbuilt browser debugger :)

Collapse
 
naucode profile image
Al - Naucode

Even better! Although I find myself going back always to the usual console functions 😂

Collapse
 
devoskar profile image
Oskar Pietrucha

I just prefer to set a debugger and then do everything inside the Dev Tools and next on copy the insights to my code.
I think it's just I have a bigger overview on what is currently happening inside the app and browser.
I don't use console.log at all

Collapse
 
dvddpl profile image
Davide de Paolis • Edited

nice and very well written post.

using just console.log in 2023 is a big no no

it was already in 2020, and 2015... because you should debugging using other other tools!
these tricks are nice and neat (and definitely helpful sometimes) but if you really want to sharpen your axe please use a proper debugger and breakpoint (and conditional breakpoints) .

Collapse
 
nazim47 profile image
Nazim Ansari

Great post! I totally agree that using just console.log in 2023 is a big no-no. With the rapid advancements in technology and the abundance of better debugging tools available, relying solely on console.log is not only inefficient but also outdated. Using more advanced debugging tools not only helps us find and fix errors faster, but also allows us to gain a deeper understanding of our code. Thanks for bringing this important topic to light!

Collapse
 
polaroidkidd profile image
Daniel Einars

Oh man, those are a bunch of really useful console loggers! I knew some of them but not all!

Going to have to update my postfix completions

Collapse
 
naucode profile image
Al - Naucode

Thanks for the amazing comment! I was also amazed when I found all of them!

Collapse
 
moibra profile image
Mohamed Ibrahim

Awesome, Very useful article

Collapse
 
israelortuno profile image
Israel Ortuño

Very great article

Collapse
 
kenslearningcurve profile image
Kenji Elzerman

I don't use front-end much in my work, but when I do I hate the Console.log. This article is awesome and learned me a lot!

Collapse
 
naucode profile image
Al - Naucode

Thank you for the awesome comment!

Collapse
 
sdedrov profile image
Seth Dedrov

very useful

Collapse
 
alptekin profile image
alptekin I.

Thanks. I was already using time console.time to have an idea on performance but for others I either had not used or didn’t know about… definitely a very beneficial content.

Collapse
 
naucode profile image
Al - Naucode

Thank you! Yeah, time is really useful. I also like the assert one.

Collapse
 
ismailco96 profile image
ismail courr

Great article, Thanks for sharing

Collapse
 
giadat1599 profile image
giadat1599

Nice post, those are really useful console loggers.

Collapse
 
naucode profile image
Al - Naucode

Thanks!

Collapse
 
ryan9119vn profile image
Ryan

Very awesome broo

Collapse
 
uploadcare profile image
Uploadcare

To be honest, all the methods described in the article were in browsers for ~10 years.

According to our experience, nobody uses them, because when you need just to log, console.log is enough. If it is not enough (e.g. for backend logs), you use some logging libraries like winston: github.com/winstonjs/winston

Collapse
 
nerdydeedsllc profile image
Nerdy Deeds, LLC

Okay, so, counterpoints:

  1. Your build script/linter should be flagging console.'s before they ever touch your repo.
  2. In those instances when one decides they should remain anyway, One should be able to rely on the developer using their own judgement.
  3. There are copious extensions for nearly every IDE that sweep the code and either auto-comment-out or outright remove every console command within the file. I run one personally that git blames each, and, if I didn't write it personally, comments them all out and then collapses their lines, so they're not even visible to me. I do this, secure in the knowledge that NONE of them - mine OR other devs' - will ever see the light of prod, since:
  4. Barring some VERY specific scenarios, END USERS should NEVER see your console output. If your deployment/minifier/uglifier doesn't scrub them you're (or more likely CICD) is doing something wrong.

Don't misunderstand me: it's a good review of console methods. But I would argue that ANY way you're using console is a no-no IN PRODUCTION, and PRIOR to Prod is a non-issue.

Collapse
 
dominikbraun profile image
DB

The best debugging tool is the one you know best. console.log offers nice out-of-the-box formatting and works fine in many situations, making it a far cry from a "big no-no".

Collapse
 
lissy93 profile image
Alicia Sykes • Edited
Collapse
 
chiefgui profile image
Guilherme Oderdenge

And has an appropriate title as well. Thank you for not click-baiting us. :)

Collapse
 
jagrutiti profile image
Jagruti Tiwari

This is article is really useful. These features are required in day to day debugging, I use to implement them manually.

Thank you for sharing this.

Collapse
 
idabaicai profile image
dabai

console.group and console.table is awesome

Collapse
 
nathannosudo profile image
Nathan Orris

Very good read. Thanks forr the article!

Collapse
 
caigengliang profile image
chase

think,i was already to use

Collapse
 
yukikimoto profile image
Yuki Kimoto

Thanks for JavaScript console information.

Collapse
 
llorx profile image
Jorge Fuentes

Clickbait title :-(

Collapse
 
higoraln profile image
Higor Allan

Omg, great article!! today i just use console.log

Collapse
 
dvalin99 profile image
Domenico Tenace

Thank you for this article, I learned some tricks I didn't know, like console.time, which I will probably abuse from now on :)

Collapse
 
sundayhd profile image
sundayhd

Too many cool stuff here , Thanks !! 💖

Collapse
 
winstonpuckett profile image
Winston Puckett

Oh my gosh, there's a console.assert function? Why did I spend all this time trying to get mocha and jest working with 11ty? This is awesome!

Collapse
 
nzomedia profile image
youssouf traore

Thanks, i forgot about console.table() it's very usefull. I didn't know some other methods.

Collapse
 
ioome profile image
sutton

Theses method is very good, it's obvious that According to the different scenarios to cope with different API.good 🥸

Collapse
 
douglasbarbosadelima profile image
Douglas Barbosa de Lima

Great article! Congratulations

Collapse
 
uttam_py profile image
Uttam Sharma

I was always using only log and error but now will use these above as well..... thanks for great article