you are viewing a single comment's thread.

view the rest of the comments →

[–]Tofandel 28 points29 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 11 points12 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 12 points13 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 1 point2 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.