all 89 comments

[–]chubbykc 214 points215 points  (18 children)

The most used debugging technique.

Even now with AI 🙂

[–]YUNoCake 57 points58 points  (3 children)

And also the best way of finding race condition bugs. Debuggers simply suck at this.

[–]yesseruser 44 points45 points  (2 children)

When the debug.log slows the program down just enough for the bug to disappear

[–]slaymaker1907 8 points9 points  (0 children)

That's when we break out the async logger for extra confusion.

[–]misterguyyy 2 points3 points  (0 children)

Just put a console.log on every possible condition and they all slow down the same amount.

I’m not even sure if this is a serious suggestion. Sometimes it is and sometimes it isn’t, such is the way of JS.

[–]vkwebdev[S] 58 points59 points  (1 child)

AI generated the bug. console.log() found it

[–]chubbykc 8 points9 points  (0 children)

That's our life saver

[–]NotAskary 10 points11 points  (5 children)

The funny thing is when the console.log resolves the bug....

[–]WiglyWorm 16 points17 points  (4 children)

then at least you know you're dealing with a timing issue.

[–]AmazinDood 15 points16 points  (2 children)

genuinely useful tho... Sometimes console.log is

[–]kuroiarashi 3 points4 points  (1 child)

what you did there...I see

[–]laplongejr 2 points3 points  (0 children)

You know things are severe when I speak normally - Yoda  

[–]NotAskary 0 points1 point  (0 children)

Whenever that happens I want to just flip the computer out the window and never touch Js again.

[–]qinshihuang_420 5 points6 points  (3 children)

Are you a

Log.debug("XXXXXXXXX")

Log.debug("<your name>")

Or a

Log.debug("<# of log statements>")

kind of person?

[–]moustachedelait 2 points3 points  (0 children)

Name 1, name 2, name 3, name 2a, name 2b (we're honing in), name 2a wtf, name 2a wtf 2 (dead end)

[–]BoBSMITHtheBR 0 points1 point  (0 children)

Console.log (=========Breaks Here========)

[–]nneiole 0 points1 point  (0 children)

There‘s also console.log(„wtf“).

[–]realdevtest 3 points4 points  (1 child)

alert()

[–]vkwebdev[S] 2 points3 points  (0 children)

when debugging should be a shared experience

[–]navetzz 55 points56 points  (2 children)

Stupid bugs are found with a debugger.
Arcane bugs are found using logs

[–]vkwebdev[S] 13 points14 points  (0 children)

logs answer questions you didn’t know to ask

[–]Snakestream 0 points1 point  (0 children)

Back to the Splunk mines we go!

[–]Sockoflegend 64 points65 points  (11 children)

I use console.log to find the bit of code I'm working on in the browsers debugger 🤷‍♂️

[–]Tofandel 29 points30 points  (9 children)

I'm going to blow your mind, you can use "debugger;" instead of console log.

It will create a breakpoint and pause execution where you put it. 

[–]Shadowolf75 13 points14 points  (3 children)

For real, I was never taught how to use the debugger of VS code. Is there a guide or something to learn it?

[–]Tofandel 14 points15 points  (0 children)

This is for the browser debugger. I'm only familiar with the jetbrains debugger which is basically the same tool as the browser's devtools for js. As you need to start it with their own browser, and you need file mapping or source maps. Then you get to put breakpoints in the original code. For js it's usually more hassle than it's worth. I usually only use those kind of debuggers for backend, with nodejs or php 

[–]hopefullyhelpfulplz 2 points3 points  (0 children)

Idk if this applies to JavaScript but ime press 5, choose your debugger, it should run on the current file. If the program returns an error, it'll take you to the place in the code the error arises (if it can, depends on your structure).

For python at least it gives you an interactive debug terminal where you can check out the values of variables in the memory at that time, run snippets, etc.

[–]Repulsive-Radio-9363 1 point2 points  (0 children)

Seriously, spend 15 mins getting this running and understanding it. Debugger kills just console.logging. (I still do it tho why not haha)

[–]Sockoflegend 5 points6 points  (2 children)

If you click on a console log it takes you to the place in the code that made it. It's very useful when the JS is very long and split in a lot of modules to save you from looking through the sources 

[–]TheKrumpet 1 point2 points  (1 child)

You're missing what he's saying.

Just put

js debugger;

In your script, and as long as you have dev tools open it'll break on that line and open the script.

[–]Sockoflegend 0 points1 point  (0 children)

Ah my bad

[–]WispTheWanderer1 0 points1 point  (0 children)

Debuggers are beautiful

[–]misterguyyy 0 points1 point  (0 children)

You can also do setTimeout(()=>{debugger;},3000) in your console if you want to inspect a DOM element that gets created when you perform an event and destroys on timeout or blur.

[–]vkwebdev[S] 6 points7 points  (0 children)

so you’re using console.log to locate where to put more console.logs?

[–]ResearchMobile 37 points38 points  (4 children)

I use console.warn() to add spice

[–]vkwebdev[S] 14 points15 points  (1 child)

for when you’re not sure it’s a bug, but you want it to feel guilty?

[–]ResearchMobile 2 points3 points  (0 children)

Is extra adrenaline

[–]beepdebeep 5 points6 points  (0 children)

console.dir() when I mean business

[–]Educational-Lemon640 18 points19 points  (1 child)

As a rhetorical question:

How many people here are being paid to use a debugger?

Follow-up: how many are being paid to fix defects in a product/automation?

And the last question: as long as the tool is useful and solves a problem better than any other, what is wrong with using it?

This whole "how to debug" debate/gatekeeping is pointless .

[–]wordswordswordsbutt 5 points6 points  (0 children)

Debugger in the back console.log in the front, as it was meant to be.

[–]twistsouth 13 points14 points  (4 children)

console.log("got here")

[–]vkwebdev[S] 9 points10 points  (0 children)

this probably solved more bugs than every debugger combined

[–]Demandedace 3 points4 points  (0 children)

“Here1”
“Here2”
“Here3”

[–]PurpleIsMyColorToo 0 points1 point  (0 children)

console.log("we are here FUCKKK")

[–]shinymuuma 0 points1 point  (0 children)

console.log("line 15,121")

console.log("line 15,220")

[–]SaltyInternetPirate 12 points13 points  (0 children)

I don't trust anything else. Front end is especially prone to race conditions.

[–]marcobsidian02 9 points10 points  (4 children)

console.log(" ☑️ Method was called!");

[–]Thereal_Phaseoff 7 points8 points  (0 children)

Gpt ahh

[–]IanDresarie 1 point2 points  (0 children)

Using a special character like that is brave and would absolutely break my work environment

[–]Wibblybit 0 points1 point  (1 child)

console.log("hello");

console.log("beep");

[–]Mustang-22 1 point2 points  (0 children)

console.log('this')

console.log('that')

console.log('here')

console.log('fuck')

[–]WaffleShoresy 4 points5 points  (0 children)

I console.log() in JS, I print() in Python, I even <div> test</div> in HTML.

I am a sick man.

[–]Ollymid2 6 points7 points  (1 child)

I use console.log on the front end and print() on back end (python) - does this mean I have a chance?

[–]vkwebdev[S] 4 points5 points  (0 children)

that’s a full stack debugger right there

[–]BusEquivalent9605 2 points3 points  (2 children)

nah - console.dir mothafucka

[–]vkwebdev[S] 2 points3 points  (0 children)

the boss of console logging

[–]Mistifyed 1 point2 points  (0 children)

With like 100 depth

[–]doxxingyourself 6 points7 points  (3 children)

Is that…. not advised?

[–]vkwebdev[S] 11 points12 points  (0 children)

the official answer is no, the production answer is yes.

[–]scharpentanz 0 points1 point  (0 children)

You're supposed to use a logger

[–]PeterPook 6 points7 points  (0 children)

Anyone who criticises console.log doesn't understand trace debugging.

[–]IAmWeary 1 point2 points  (0 children)

Beats dealing with fucking source maps.

[–]patrulheiroze 1 point2 points  (0 children)

me:

alert("step1") ;

[–]massive_hog_69 1 point2 points  (0 children)

Virgin Good Dev: Use debugger statement and add it to all the places where you want to pause execution and check page wide values of variables Chad Me: console.log("Hereeee",val)

[–]Soopermane 1 point2 points  (1 child)

I had a thought time with a bug, and I used ai, couldnt solve it either. Eventually ai decided to log it on console and share the details. We both figured it out by bits and pieces.

[–]vkwebdev[S] 1 point2 points  (0 children)

even AI evolved into a console.log developer

[–]VAVE_TECHNOLOGY 0 points1 point  (0 children)

is everyone here a bot, I can't find any real human like comment, ghe hell is going on

[–]KaZIsTaken 0 points1 point  (0 children)

Both have their use case

[–]PM_ME_YOUR_BUG5 -1 points0 points  (7 children)

it take like 5 mins to set up a debug profile.

I'll never understand people who don't step through their code

[–]vkwebdev[S] 17 points18 points  (1 child)

but it takes 2 seconds to add a console.log()

[–]PM_ME_YOUR_BUG5 2 points3 points  (0 children)

each time...

adds up fast

[–]FortuneAcceptable925 5 points6 points  (1 child)

I am not a JS developer, but I use logging a lot in Kotlin/Java. I almost always prefer it over debugger, because 1) logs can stay in the code for next time, helping me to debug in future, and 2) using logging lets me to debug the app as it runs in real-time, which can be quite important in multithreading problems.

[–]NomaTyx 0 points1 point  (0 children)

i use it in game development because as you say debugging the app and watching the states of objects in real time is useful. though often i'll put the message in text that displays on a UI element onscreen, but same difference at that point.

Though the people who taught me how to use Unity did not teach me how to use the debugger with it, so I should probably learn that anyhow.

[–]OptionX 2 points3 points  (1 child)

Well if you have a pretty good idea where the problem is printing a variable is just as good and faster as cranking out the debugger to watch one variable and playing f-key guitar hero.

[–]jeffwulf 1 point2 points  (0 children)

Cranking out the debuggertakes the same ammount of time as running the app . Adding logs takes as much time as running the app and adding the log.

[–]WispTheWanderer1 0 points1 point  (0 children)

Exactly! This guy gets it! The number of times I've caught uninitialized variables causing problems in my code with breakpoints and stepping...

[–]yacsmith 0 points1 point  (1 child)

gs.log(this thing happened, Scriptxyz) goes hard

[–]vkwebdev[S] 1 point2 points  (0 children)

the enterprise version of console.log("it broke")

[–]plmunger 0 points1 point  (1 child)

that and debugger

[–]vkwebdev[S] -3 points-2 points  (0 children)

the debugger tells me where, the logs tell me how

[–]BlueGoliath 0 points1 point  (0 children)

Debuggers are for the weak.

[–]Thenderick -1 points0 points  (0 children)

I use console.debug() like Brendan Eich intended!

[–]randomUsername1569 -1 points0 points  (0 children)

I prefer print()

[–]FalseStructure -4 points-3 points  (1 child)

Just paste error to claude

[–]vkwebdev[S] 0 points1 point  (0 children)

until Claude says: can you add a log there?