Tips and Tricks for Debugging JavaScript

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 28. 02. 2022
  • Want to know how to become a better JavaScript developer? Well, the more efficiently you can debug your code, the better off you'll be. In this video, you'll learn about helpful functions to use other than just console.log(). You'll also see how to use the debugger statement as well as set up true debugging inside of VS Code.
    Advent of JS - www.adventofjs.com/
    STAY IN TOUCH 👋
    Check out the Podcast - compress.fm
    Newsletter 🗞 - www.jamesqquick.com/newsletter
    Live streams on Twitch đŸ–„ïž - / jamesqquick
    Follow me on Twitter 🐩 - / jamesqquick
    QUESTIONS...?
    Join the Discord Server 💬 - / discord
    Want to know what hardware and software I use? www.jamesqquick.com/uses
    Learn Web Development 📖 - www.jamesqquick.com/courses

Komentáƙe • 269

  • @ilijatrbogazov4579
    @ilijatrbogazov4579 Pƙed 2 lety +185

    You missed, console.trace , super useful to know the call stack when debugging complex applications

  • @AdamGaffney96
    @AdamGaffney96 Pƙed 2 lety +50

    Honestly the biggest piece of advice that I have to beginners and even some intermediates really is to just read the error messages. I can't possibly counts the amount of people who post on forums asking "why is my code broken?" and post an error message that says on line 30 there's an unexpected bracket. ALWAYS always read the error messages thoroughly before asking for help.

  • @florinbujoreanu1020
    @florinbujoreanu1020 Pƙed 7 měsĂ­ci +5

    you saved my life with this little piece of knowledge that apparently you don't find anywhere straightforward..

  • @geraldleroy2225
    @geraldleroy2225 Pƙed 2 lety +40

    I wasn't aware that console.assert(), console.time() and console.timeEnd() existed. I also found the tips re: debugging in VS Code to be helpful. Also the reminder to step away is always a good reminder. Thanks for taking the time to put this helpful video together.

  • @alejandro.mangione
    @alejandro.mangione Pƙed 2 lety +6

    Something that I didn't see you mentioning was that when you add a debugger, you can also use the console at that scope. I find that really useful.

  • @EdwinPWeston
    @EdwinPWeston Pƙed 2 lety

    Wow, thanks so much!. I don't know how many times I set a breakpoint in Chrome and press F5 to continue running as if I was in Visual Studio (C#) and reloaded my app. This was SO helpful!

  • @gabrielv1856
    @gabrielv1856 Pƙed 2 lety +3

    I personally use styled console.logs for warnings, alerts and oks. If theres another kind of message i can change styles also is a bit limited but for me is good enough. Thanks for the video! Ive been thinking about this lately and makes me want to build my own mini debugger i can use on every project. Again, thanks!

  • @Sledgeh101
    @Sledgeh101 Pƙed 2 lety +14

    The console.table one alone made this video worth it! Thanks so much!

  • @MuratKeremOzcan
    @MuratKeremOzcan Pƙed 2 lety +7

    The most clear and concise content I've seen on the topic, thanks

  • @AlleyDev
    @AlleyDev Pƙed 2 lety +2

    I only said a couple weeks ago to a couple of colleages that there isnt many helpful resources out there to help with debugging, and its not something you generally get taught/shown on courses. Thank you, this has been super helpful for me as a junior, especially as I want to become more efficient at debugging and move away from console.logging everything!

  • @jesusvegaguerrero2752
    @jesusvegaguerrero2752 Pƙed 2 lety

    so good tips for debug projects.. thank you for the video James!

  • @willadams6217
    @willadams6217 Pƙed 2 lety +2

    Yeah excited to hear you have entered the Vim world. I think the VS Code extension is a great entry to Vim, keep us updated please.

  • @fiona2322
    @fiona2322 Pƙed 2 lety

    Thank you so much, this is going to be very very useful!!!

  • @invictuz4803
    @invictuz4803 Pƙed 2 lety +92

    I think in many non-trivial real world scenarios like when you need to debug a web app in production that uses a library, it's more practical to use just the browser developer tools to debug - adding DOM/Event Listener breakpoints, watch expressions, black boxing library code, etc.. One thing that stumps me is that when I try to inspect event handlers that are registered on a button, I usually only see minified library code which doesn't help. I think doing a video on all the Chrome DevTools debugging features would be really helpful, and also when it wouldn't work like when code is obfuscated on the client.

    • @undefinedvariable8085
      @undefinedvariable8085 Pƙed 2 lety +16

      Agreed. I came here expecting this video to cover more browser runtime debugging solutions with DevTools.
      Don't care much for logging objects out in table format and most intermediate developers are most likely already familiar with all the other console methods mentioned.

    • @kigerukage6641
      @kigerukage6641 Pƙed 2 lety +2

      I definitely agree, I have spent countless hours trying to find out where a legacy application is failing hard on new requirements and I have to hunt down event listeners and the like for clues. In the Sources tab of the developer tools there is a button {} that will help format minified files to make it easier to read

    • @SebastianZartner
      @SebastianZartner Pƙed 2 lety +5

      Regarding minified library code, the browser DevTools also support source maps. That means, they maps the minified statements to the original code for debugging.
      Another thing related to that is that the Firefox DevTools show when they recognize code of a specific library like React, Angular, etc. That makes it a little easier to black box them.

  • @developerpranav
    @developerpranav Pƙed rokem

    Assert and debugging is really useful, thank you!

  • @jdmji
    @jdmji Pƙed 2 lety

    Awesome, the console table is awesome to know about!

  • @skippyzk
    @skippyzk Pƙed 2 lety +4

    you're the best man. this is literally the last quesiton on these interview questions (my friend is a team lead and sent me the interview quesitons lol)
    "...Can you please describe 3 ways you could use the Developer Tools in the browser to further debug the impacted Javascript."
    my rough draft answer right now is
    1) check the console for errors
    2) check event listeners and breakpoints
    3) use debugger; and console.log/dir/table/assert/time/timeLog/TimeEnd/warn/error/count/countEnd/trace

  • @vince-sig1014
    @vince-sig1014 Pƙed 2 lety +1

    i honestly cant wait to try this out and show this to my colleagues! Thank you so much!

  • @saketabhishek5147
    @saketabhishek5147 Pƙed 2 lety +1

    Thanks for sharing I love your video !!Please keep posting

  • @karlstenator
    @karlstenator Pƙed 2 lety

    Thank you kind sir. Console.table has been my go to since day dot.

  • @user-tb7dh4dl2x
    @user-tb7dh4dl2x Pƙed 2 lety +8

    Would be useful making a video on spa debugging experience on the big three (vue react angular) or debugging experience on some js code that pushed thrue webpack.

  • @pierrekilgoretrout3143
    @pierrekilgoretrout3143 Pƙed 2 lety

    Thank you, I did not know the table and dir operations in console.

  • @ssygon2
    @ssygon2 Pƙed 2 lety +1

    Wow, i didn't know "debugger" existed! Useful for debugging inline js(non external js file), which i couldn't set a breakpoint on! 👍

  • @alexhou76508
    @alexhou76508 Pƙed 2 lety

    Very useful. Thank you!

  • @JorgeIvanSandoval
    @JorgeIvanSandoval Pƙed 2 lety

    Super helpful dude, thanks for sharing!!!

  • @BG-fo4si
    @BG-fo4si Pƙed 2 lety +7

    Didn't know console has so many different methods 😅 Thank you for this material

  • @teminoah2960
    @teminoah2960 Pƙed 2 lety

    Great video,James this is so significant
    Thanks so much

  • @SebastianZartner
    @SebastianZartner Pƙed 2 lety +18

    Btw. if you really want to log something, you don't even have to modify your code by inserting console.log(). The debuggers in the DevTools and VSCode allow to set so-called logpoints. Those work similar to breakpoints but log the variables you provide like a console.log() at that line of code where you set them.

  • @rachellejanssen2655
    @rachellejanssen2655 Pƙed 2 lety

    And here I thought it was some kind of video about debuggers and breakpoints, but half of it is actually about console.logging like a boss!

  • @thomad8538
    @thomad8538 Pƙed 2 lety

    You're the BEST, Thanks so much.

  • @alx_z1
    @alx_z1 Pƙed 2 lety

    This has just become my fav video on youtube. Cheers

  • @muhammadumarsotvoldiev8768
    @muhammadumarsotvoldiev8768 Pƙed 5 měsĂ­ci

    Thank you very much! Very helpfull

  • @felipesakuma9882
    @felipesakuma9882 Pƙed 2 lety +3

    which theme you use? It's beautiful

  • @devstefancho
    @devstefancho Pƙed 2 lety +1

    I already know console.dir shows more information than log, but element usage of console.dir is very impressive!

  • @andresruedalibre
    @andresruedalibre Pƙed 4 měsĂ­ci

    Thanks James, this was very useful!

  • @patrickconrad396
    @patrickconrad396 Pƙed rokem +3

    My dude my favorite tip has to be throwing variables is an object for console logs. So simple but so freaking useful. I'm mad I never thought of it before. Thank you!

  • @hsdev
    @hsdev Pƙed rokem

    Very helpful video. Thanks! James.

  • @accsuperstar
    @accsuperstar Pƙed 2 lety

    Great stuff as always

  • @nickwoodward819
    @nickwoodward819 Pƙed 2 lety

    Nice video - does it matter where you put the debugger statement if you're also adding break points?

  • @fer-ri
    @fer-ri Pƙed 2 lety

    Never knew about console.table .. Thanks 👍

  • @bravoprochu
    @bravoprochu Pƙed 2 lety

    vsCode debugging only, but Your tips for console - awesome!

  • @sidneirocha7639
    @sidneirocha7639 Pƙed 2 lety

    Great video. Thanks, James

  • @HelderOliveira
    @HelderOliveira Pƙed rokem

    Amazing! Thank you

  • @marckk17
    @marckk17 Pƙed rokem

    I was looking for a normal crack for a long time and stumbled upon you, thank you very much

  • @kadscar
    @kadscar Pƙed 2 lety

    Amazing, thanks !

  • @oleksandrkovalov1543
    @oleksandrkovalov1543 Pƙed 2 lety

    Thank you for the video. Maybe you could create a video about debugging TypeScript using debugger in VS Code ?

  • @Mike----
    @Mike---- Pƙed 2 lety

    Great! Thank you for the help

  • @shokresistant123
    @shokresistant123 Pƙed 2 lety

    Fantastic Video! Thanks!

  • @chandlerchen2192
    @chandlerchen2192 Pƙed 2 lety +2

    What is the theme you are using in VS code? It looks really nice!

  • @markemerson98
    @markemerson98 Pƙed 2 lety

    nice - didn't know about the dir, or the {} console options

  • @isaacny
    @isaacny Pƙed 2 lety

    Duuude I've been debugging with stone age techniques..... Thaaaanks!!! Fastest Liked + subscribed I've ever done 😆

  • @brendanfarquharson1874
    @brendanfarquharson1874 Pƙed 2 lety

    Console table will be handy. Thanks

  • @Xe054
    @Xe054 Pƙed 2 lety +13

    Great video 👍. Side note: when you impersonate different people, it might help to face the characters against each other (person one looks right, person two looks left).

    • @JamesQQuick
      @JamesQQuick  Pƙed 2 lety +1

      haha yeah I'll get better at this!

  • @luke-urban
    @luke-urban Pƙed 2 lety +2

    I did enjoy the video, the assert is something new for me. Also try turbo console log (vscode plugin) 😉 I recently discovered it 🔎

    • @JamesQQuick
      @JamesQQuick  Pƙed 2 lety

      Yeah I’ve been meaning to do a video on it!

    • @luke-urban
      @luke-urban Pƙed 2 lety

      @@JamesQQuick Nice!

  • @rajnarayananv
    @rajnarayananv Pƙed 2 lety

    Great. Thank you

  • @zoa_photo
    @zoa_photo Pƙed rokem

    Honestly, it's been fifteen years since I began coding as an amateur, still an amateur today. But I always stuck with my console.log as a multimeter pin, I thought I needed nothing else ... I thought.
    If I could give you 10 thhumbs up I would ! ^^

  • @RandomAlexus
    @RandomAlexus Pƙed rokem

    Extremely helpful video!

  • @user-qp6yp4qk9i
    @user-qp6yp4qk9i Pƙed 2 lety

    3:52 didn't know about that. big thanks

  • @Apple55330
    @Apple55330 Pƙed 7 měsĂ­ci

    Fantastic! Thanks for the video!

  • @jailsonnt
    @jailsonnt Pƙed 2 lety

    I tried to debug with vscode but with a typescript code, it worked but the code was unfortunatelly translated to js, nevertheless, great video, very helpful, if you have some tips to do similar things with typescript I'll watch

  • @kirillrotanov7291
    @kirillrotanov7291 Pƙed rokem

    Thank you!

  • @Pareshbpatel
    @Pareshbpatel Pƙed 2 lety +1

    Great introduction on Debugging in JavaScript. - Thanks, James
    {2022-03-09}

  • @ExtremeCrashCam
    @ExtremeCrashCam Pƙed rokem +1

    Console commands seemed so useful until my code started getting really complicated. Thanks for the debugger tips, using dev tools on chrome would have saved me so much time in my last project.

  • @NeverCodeAlone
    @NeverCodeAlone Pƙed 2 lety

    Magic and so good thx for your passion

  • @hassaneoutouaya
    @hassaneoutouaya Pƙed 2 lety

    THANK YOU!

  • @kadscar
    @kadscar Pƙed 2 lety

    Amazing, thanks ! Do you know if it works with VSCode Remote ?

  • @swapnilcodes
    @swapnilcodes Pƙed 2 lety

    Wow...can you tell me the which font family you used in the vs code... it's looking awesome
    ..😍👌

  • @jesper.ordrup
    @jesper.ordrup Pƙed 2 lety +1

    Debugging is so much more powerful than console logging. Being able to pause execution (breakpoint) and discover what really goes on (step through a flow) because of the state of variables (you can see all variable values - and even change them for testing) is so so so more much valuable.
    And you don't modify your code.
    Serverside code debugging can be tough to setup, though. That's could be a follow up video

    • @jcoucelanga4373
      @jcoucelanga4373 Pƙed 2 lety

      also you can log that same variable and know what is going on

    • @dingusfartacus9624
      @dingusfartacus9624 Pƙed 2 lety

      @@jcoucelanga4373 try doing it 30 times over, and logging 20 variables. Just not the same.

    • @jcoucelanga4373
      @jcoucelanga4373 Pƙed 2 lety +1

      @@dingusfartacus9624 Meh, I insist, some specific issues demand debugging, but 99% you can do it faster with advanced logs

  • @peepforlearning6058
    @peepforlearning6058 Pƙed 2 lety

    Thanks, usefull

  • @deltaforce3329
    @deltaforce3329 Pƙed 7 měsĂ­ci

    Thank you Sir !!

  • @Russell.Jolly.2023
    @Russell.Jolly.2023 Pƙed 2 lety

    Important for developers to know.

  • @florinbujoreanu1020
    @florinbujoreanu1020 Pƙed 7 měsĂ­ci

    thx man!

  • @CafeAsp
    @CafeAsp Pƙed rokem

    Great info.

  • @jamesjones2212
    @jamesjones2212 Pƙed 2 lety

    I have a monorepo project i work with, and the debugging by default takes a huge amount of time so i need to configure the "outFile" property. Could you make a video showing the debugging of something like a monorepo that uses lerna?

  • @Peter-vz4tb
    @Peter-vz4tb Pƙed 2 lety

    Cool, thank you

  • @vishwasrvibhu6670
    @vishwasrvibhu6670 Pƙed 2 lety +2

    Great video! Can you please also tell me the font and theme of VS Code you are using?

  • @maxwilsonpereira
    @maxwilsonpereira Pƙed 2 lety

    Nice! Thanks! 🙂

  • @annakanteladze3626
    @annakanteladze3626 Pƙed 2 lety

    Thanks!

  • @fliplucky8813
    @fliplucky8813 Pƙed 2 lety +1

    vim plug

  • @matm7472
    @matm7472 Pƙed 2 lety

    Great job, thank you!

  • @damirmubarakshin1811
    @damirmubarakshin1811 Pƙed 2 lety +1

    Awesome tips! Thanks!
    By the way, what is the name of your vscode color theme?

    • @paci
      @paci Pƙed 2 lety

      have you found out? he is not 'quick' responding

  • @DarrenJohn10X
    @DarrenJohn10X Pƙed 2 lety

    @3:50 = syntactical sugar. {length} simply creates a new object {length: length} ... useful for debugging sure but it's a feature of Javascript overall, not just for debugging

  • @LukasPlaysMusic
    @LukasPlaysMusic Pƙed 2 lety +1

    Great video 👍

  • @shakthifuture
    @shakthifuture Pƙed 2 lety

    Nice information.

  • @parth1450
    @parth1450 Pƙed 2 lety

    Just one question
    Which theme is that..name please?
    Thanks..
    I really liked it

  • @nouribenz
    @nouribenz Pƙed 2 lety

    Thank you

  • @greatkingrat
    @greatkingrat Pƙed 2 lety +2

    Problem I find with console.table vs console.log is when there are a lot of variables inside the array or json. console.table tries to squeeze them all into the window. Sure you can expand it out with the mouse but then you hit the responsive view and sometimes there is responsive specific code. console.log might be dirty but sometimes it just works. console.time is a nifty tool!

  • @milimol2008
    @milimol2008 Pƙed 2 lety

    Nice, learned a couple of console methods I wasn’t aware of (never had to use them). But, why wouldn’t you use the developer tools in the browser? Same results, less effort.

  • @neontuts5637
    @neontuts5637 Pƙed 2 lety +2

    Thanks for the video. [Q] - Debugger in vscode is built-in or do we need to install the "Debugger for Chrome" extension?

    • @JamesQQuick
      @JamesQQuick  Pƙed 2 lety +5

      It’s built in now :)

    • @neontuts5637
      @neontuts5637 Pƙed 2 lety +1

      @@JamesQQuick Wow that's cool. Thanks You :)

  • @sivaprasadev3361
    @sivaprasadev3361 Pƙed 2 lety +1

    Nice. What theme are you using in VS code? I really loved the cursor animation.

    • @harag9
      @harag9 Pƙed 2 lety

      The cursor animation is a setting in VS code, no matter on the theme - forgot the name but look in the settings and search for "font"

    • @leoMC4384
      @leoMC4384 Pƙed 2 lety

      I think the theme is ugly as fuck but the cursor animation is something from VS Code, I don't remember the name of setting though.

    • @anbk
      @anbk Pƙed 2 lety +3

      "editor.cursorBlinking": "expand"

  • @equiman
    @equiman Pƙed 2 lety

    I've also recommend an Extension called Turbo Console Log 👌😎

  • @teminoah2960
    @teminoah2960 Pƙed 2 lety

    Great teacher

  • @costantino03
    @costantino03 Pƙed 2 lety

    what color do you use for the Cobalt 2 theme?

  • @codinghubfree
    @codinghubfree Pƙed 2 lety

    Could you please tell which theme you are using?

  • @umeshhbhat
    @umeshhbhat Pƙed 2 lety

    Any idea how to view Mongo doc id during debugging? Debugger usually shows the binary value for them.

  • @christianrodier3381
    @christianrodier3381 Pƙed 2 lety

    That is really cool!

  • @alexalexander4326
    @alexalexander4326 Pƙed 2 lety

    In complex apps based on react IDE debugging does not work so well as in Chrome. In IDE it tracks many internal processes coming out from react itself and which is useless to track. In Chrome it works much better way as you can stop interpretator and see all vars around and type code in console and it does not track internal react code coming from library

  • @Knards
    @Knards Pƙed 2 lety

    Thanks James. I just found out I dont know everything :)

    • @JamesQQuick
      @JamesQQuick  Pƙed 2 lety +1

      hahaha everyone has something to learn every day!

  • @kishorpatel1254
    @kishorpatel1254 Pƙed 2 lety +6

    You look really tired buddy, take some rest. We like you content but you will be able to keep making it only if you take care of your health. Wishing more power to creators and contributors like you.

    • @aaditkamat4995
      @aaditkamat4995 Pƙed rokem

      Yeah I noticed that as well. Glad someone else pointed it out too. Take care @James Q Quick!

  • @borasumer
    @borasumer Pƙed 2 lety

    What extension is that gives you the animated text cursor? That is so cool.

    • @JamesQQuick
      @JamesQQuick  Pƙed 2 lety

      It's a setting called like cursor style I think lol