Fireship · @fireship

Beyond Console Log in 100 Seconds

Uploaded February 18, 2020 · Length 1:44

Beyond Console Log in 100 Seconds

Summary

console.log tricks and shortcuts in JavaScript for debugging and logging.

  • console.log
  • javascript debugging
  • logging tricks
  • console group
  • console count
  • console time
  • console trace

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    console it's the browsers built-in

  2. 0:02

    debugger you may have heard of it before

  3. 0:03

    but try running console log console it

  4. 0:05

    does a lot more than you may have

  5. 0:06

    realized in some cases you only want to

  6. 0:09

    console log something if a condition is

  7. 0:11

    false in that case you're probably

  8. 0:12

    looking for assert when the first

  9. 0:14

    argument is false it logs the second

  10. 0:16

    argument as an error

  11. 0:17

    another trick you'll often see people do

  12. 0:19

    is use console.log along with braces to

  13. 0:22

    provide labels for the things that

  14. 0:23

    they're logging that's cool in all but

  15. 0:24

    change log to table and you get a much

  16. 0:26

    prettier output as j/s developers we

  17. 0:29

    often like to abuse console and that can

  18. 0:31

    make things pretty messy use console

  19. 0:32

    group to group things together with a

  20. 0:34

    label then collapse them by default to

  21. 0:36

    save space in the console things can

  22. 0:38

    also get ugly if you're logging a bunch

  23. 0:39

    of objects changelog Tudor and you get a

  24. 0:42

    much cleaner triangle drop-down do you

  25. 0:44

    ever find yourself manually incrementing

  26. 0:46

    a number in your console logs if so you

  27. 0:48

    might be able to save your sanity by

  28. 0:50

    using console count it takes an optional

  29. 0:52

    label and every time it's called it will

  30. 0:54

    increment the count by one on a similar

  31. 0:56

    note you can also keep track of the

  32. 0:58

    amount of time between your console logs

  33. 1:00

    calling time will start a timer then

  34. 1:02

    time log will log the amount of time you

  35. 1:04

    elapsed since that timer started now in

  36. 1:06

    JavaScript we're often working in the

  37. 1:08

    context of deeply nested functions and

  38. 1:10

    objects when debugging it may be

  39. 1:11

    necessary to traverse through the stack

  40. 1:13

    trace of your code use console trace in

  41. 1:16

    the function you would expect to be at

  42. 1:17

    the top of the call stack and now we can

  43. 1:19

    see exactly what happened before this

  44. 1:20

    function was pushed on to the top of the

  45. 1:22

    call stack and lastly every good Jas

  46. 1:24

    developer should give their console logs

  47. 1:26

    some flair use % C as the first

  48. 1:29

    character in a string then pass in some

  49. 1:30

    CSS styling as your second argument and

  50. 1:33

    now the console is your canvas if you

  51. 1:35

    want to see more short videos like this

  52. 1:36

    make sure to hit the like button thanks

  53. 1:38

    for watching and I will see you in the

  54. 1:40

    next one

  55. 1:42

    you