#100DaysOfWeb in Python Transcripts
Chapter: Days 25-28: JavaScript Introduction
Lecture: Common JS gotchas

Login or purchase this course to watch this video and the rest of the course contents.
0:01 JavaScript gotchas.
0:04 It's important to acknowledge that JavaScript
0:06 was designed in 10 days.
0:10 Gary Bernhardt, in his inspiring talk
0:13 The Birth and Death of JavaScript, shows this
0:16 in relation to the time it took to design Closure
0:20 and you see it was very fast.
0:24 And that led to some weird decisions
0:27 in the design and here he shows some examples.
0:31 Go watch this talk.
0:33 It's not only highly entertaining, and inspiring
0:36 but also visionary 'cause a lot of what he said
0:39 five years ago is actually very relevant today.
0:45 So what are some common JavaScript gotchas?
0:49 Well, the most important thing
0:50 are global variables.
0:52 As per best programming practices
0:54 the less isolated something is the less reliable.
0:58 Make something global and it can change
1:01 in multiple locations.
1:03 We've already seen that
1:04 if you use the var keyword to initialize variables
1:08 those variables can easily be
1:10 clobbered in outer namespaces.
1:13 So you should use let and const.
1:17 JavaScript has C-style block syntax
1:20 but not its block scope.
1:22 No information hiding.
1:24 In the same vein, the flexibility of JavaScript
1:28 allows you to omit semi-colons
1:30 at the end of your statements.
1:32 Which usually is not a problem
1:34 unless you space your code in a certain way
1:37 then errors again pass silently.
1:40 So make sure you use semi-colons
1:43 to not run that risk.
1:47 And there are two equality operators.
1:49 If you use double equals sign
1:51 to compare number one and string one
1:55 it would say that they were equal.
1:57 But that might not be what you want
1:59 because although they look the same
2:02 they're not from the same data type.
2:04 So it's recommended to use triple quotes
2:07 which not only compares the values
2:10 but also the types.
2:11 So in that case
2:13 number one and string one would not be the same.
2:17 And, similarly there are two ways
2:19 to say that something is null, or undefined.
2:23 Where Python for example only has none
2:25 and it still confuses me
2:27 which one is used in which scenario.
2:31 Remember, errors should never pass silently
2:34 according to Python, unless explicitly silenced.
2:38 There should be one, and preferably only one
2:41 obvious way to do things.
2:42 And namespaces are one honking great idea.
2:45 And of course this is a lesson on JavaScript.
2:48 It's not Python.
2:49 But looking at the inner works
2:51 of JavaScript, I both appreciate Python a lot
2:54 for its design, but I can also see how JavaScript
2:58 is dynamic and easy to get started with.
3:01 It's just that you have to keep
3:03 these kinds of gotchas in mind
3:05 when you're programming JavaScript
3:07 to rule out any unnecessary risks.
3:10 And this is a very high level
3:12 overview of JavaScript.
3:13 And in the last video, I'm going to
3:15 point you to some resources
3:17 so you can keep studying JavaScript.
3:20 Because again, it's used everywhere
3:22 and the web is running on JavaScript.
3:24 So any time you can invest learning this language
3:28 is time well spent.