Fireship · @fireship
JavaScript Pro Tips - Code This, NOT That
Uploaded September 27, 2018 · Length 12:37
Summary
javascript pro tips for writing good code with modern features and avoiding bad practices, including debugging, console logging, and concise coding techniques.
- javascript pro tips
- console logging
- debugging
- code optimization
- javascript best practices
- modern javascript
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
[Music]
- 0:06
javascript is a programming language
- 0:08
that people love to hate a long time ago
- 0:11
developers used to pride themselves on
- 0:12
being back in developers because it was
- 0:14
more challenging and complex javascript
- 0:17
was just a toy for annoying people on
- 0:18
websites but it's 2019 and today we have
- 0:23
tools like the cloud docker and many API
- 0:26
is that abstract way the complexity of
- 0:28
back-end development if you're starting
- 0:29
up a company today there's a good chance
- 0:31
you'll do the majority of your
- 0:32
development on the front end with
- 0:34
JavaScript so today I want to show you
- 0:35
how to write good JavaScript with modern
- 0:37
features and avoid bad JavaScript if
- 0:39
you're just finding me like and
- 0:40
subscribe and if you have your own
- 0:42
JavaScript pro tips let me know in the
- 0:43
comments one lucky comment will win this
- 0:45
one-of-a-kind t-shirt via livestream
- 0:47
next week
- 0:49
so the first thing you need to know is
- 0:51
how to debug your JavaScript like a pro
- 0:54
and the way we do that of course is by
- 0:56
console logging stuff and I'm saying
- 0:58
that with a straight face there are good
- 0:59
ways to console log and bad ways let's
- 1:02
imagine we have three different objects
- 1:03
each one assigned to its own variable
- 1:04
the obvious way to log these is just one
- 1:07
after the other but the main problem is
- 1:08
we don't know the name of the variable
- 1:09
when this gets logged but there's a
- 1:11
trick we can use here called computed
- 1:13
property names where we add the
- 1:14
variables to an object not only does
- 1:16
this reduce the code footprint but it
- 1:18
also tells us exactly which variable
- 1:19
define this data one line of code one
- 1:22
console log and all the information we
- 1:24
need but maybe this data is extra
- 1:25
important so we want to make it stand
- 1:27
out with some custom CSS styling you can
- 1:29
substitute data and also CSS styles by
- 1:32
using a percent sign so we'll add
- 1:33
percent C and then have the second
- 1:35
argument be our actual CSS style and now
- 1:38
we get this bold orange color in the
- 1:39
console one thing you might have noticed
- 1:41
is that the objects all share common
- 1:43
properties so maybe we could display
- 1:44
those as a table this is really useful
- 1:46
when you have an array of objects just
- 1:48
do console table with the array I could
- 1:51
probably do a whole video on console
- 1:52
logging so I'll just show you a couple
- 1:54
more things here if you're benchmarking
- 1:55
performance you can actually keep track
- 1:57
of time in the console will first define
- 1:59
our timer and we'll give it a name of


