Fireship · @fireship
Beyond Console Log in 100 Seconds
Uploaded February 18, 2020 · Length 1:44
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.
- 0:00
console it's the browsers built-in
- 0:02
debugger you may have heard of it before
- 0:03
but try running console log console it
- 0:05
does a lot more than you may have
- 0:06
realized in some cases you only want to
- 0:09
console log something if a condition is
- 0:11
false in that case you're probably
- 0:12
looking for assert when the first
- 0:14
argument is false it logs the second
- 0:16
argument as an error
- 0:17
another trick you'll often see people do
- 0:19
is use console.log along with braces to
- 0:22
provide labels for the things that
- 0:23
they're logging that's cool in all but
- 0:24
change log to table and you get a much
- 0:26
prettier output as j/s developers we
- 0:29
often like to abuse console and that can
- 0:31
make things pretty messy use console
- 0:32
group to group things together with a
- 0:34
label then collapse them by default to
- 0:36
save space in the console things can
- 0:38
also get ugly if you're logging a bunch
- 0:39
of objects changelog Tudor and you get a
- 0:42
much cleaner triangle drop-down do you
- 0:44
ever find yourself manually incrementing
- 0:46
a number in your console logs if so you
- 0:48
might be able to save your sanity by
- 0:50
using console count it takes an optional
- 0:52
label and every time it's called it will
- 0:54
increment the count by one on a similar
- 0:56
note you can also keep track of the
- 0:58
amount of time between your console logs
- 1:00
calling time will start a timer then
- 1:02
time log will log the amount of time you
- 1:04
elapsed since that timer started now in
- 1:06
JavaScript we're often working in the
- 1:08
context of deeply nested functions and
- 1:10
objects when debugging it may be
- 1:11
necessary to traverse through the stack
- 1:13
trace of your code use console trace in
- 1:16
the function you would expect to be at
- 1:17
the top of the call stack and now we can
- 1:19
see exactly what happened before this
- 1:20
function was pushed on to the top of the
- 1:22
call stack and lastly every good Jas
- 1:24
developer should give their console logs
- 1:26
some flair use % C as the first
- 1:29
character in a string then pass in some
- 1:30
CSS styling as your second argument and
- 1:33
now the console is your canvas if you
- 1:35
want to see more short videos like this
- 1:36
make sure to hit the like button thanks
- 1:38
for watching and I will see you in the
- 1:40
next one
- 1:42
you


