Fireship · @fireship

JavaScript Pro Tips - Code This, NOT That

Uploaded September 27, 2018 · Length 12:37

JavaScript Pro Tips - Code This, NOT That

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.

  1. 0:00

    [Music]

  2. 0:06

    javascript is a programming language

  3. 0:08

    that people love to hate a long time ago

  4. 0:11

    developers used to pride themselves on

  5. 0:12

    being back in developers because it was

  6. 0:14

    more challenging and complex javascript

  7. 0:17

    was just a toy for annoying people on

  8. 0:18

    websites but it's 2019 and today we have

  9. 0:23

    tools like the cloud docker and many API

  10. 0:26

    is that abstract way the complexity of

  11. 0:28

    back-end development if you're starting

  12. 0:29

    up a company today there's a good chance

  13. 0:31

    you'll do the majority of your

  14. 0:32

    development on the front end with

  15. 0:34

    JavaScript so today I want to show you

  16. 0:35

    how to write good JavaScript with modern

  17. 0:37

    features and avoid bad JavaScript if

  18. 0:39

    you're just finding me like and

  19. 0:40

    subscribe and if you have your own

  20. 0:42

    JavaScript pro tips let me know in the

  21. 0:43

    comments one lucky comment will win this

  22. 0:45

    one-of-a-kind t-shirt via livestream

  23. 0:47

    next week

  24. 0:49

    so the first thing you need to know is

  25. 0:51

    how to debug your JavaScript like a pro

  26. 0:54

    and the way we do that of course is by

  27. 0:56

    console logging stuff and I'm saying

  28. 0:58

    that with a straight face there are good

  29. 0:59

    ways to console log and bad ways let's

  30. 1:02

    imagine we have three different objects

  31. 1:03

    each one assigned to its own variable

  32. 1:04

    the obvious way to log these is just one

  33. 1:07

    after the other but the main problem is

  34. 1:08

    we don't know the name of the variable

  35. 1:09

    when this gets logged but there's a

  36. 1:11

    trick we can use here called computed

  37. 1:13

    property names where we add the

  38. 1:14

    variables to an object not only does

  39. 1:16

    this reduce the code footprint but it

  40. 1:18

    also tells us exactly which variable

  41. 1:19

    define this data one line of code one

  42. 1:22

    console log and all the information we

  43. 1:24

    need but maybe this data is extra

  44. 1:25

    important so we want to make it stand

  45. 1:27

    out with some custom CSS styling you can

  46. 1:29

    substitute data and also CSS styles by

  47. 1:32

    using a percent sign so we'll add

  48. 1:33

    percent C and then have the second

  49. 1:35

    argument be our actual CSS style and now

  50. 1:38

    we get this bold orange color in the

  51. 1:39

    console one thing you might have noticed

  52. 1:41

    is that the objects all share common

  53. 1:43

    properties so maybe we could display

  54. 1:44

    those as a table this is really useful

  55. 1:46

    when you have an array of objects just

  56. 1:48

    do console table with the array I could

  57. 1:51

    probably do a whole video on console

  58. 1:52

    logging so I'll just show you a couple

  59. 1:54

    more things here if you're benchmarking

  60. 1:55

    performance you can actually keep track

  61. 1:57

    of time in the console will first define

  62. 1:59

    our timer and we'll give it a name of