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


Talk Python's Mastodon Michael Kennedy's Mastodon