#100DaysOfWeb in Python Transcripts
Lecture: Variables (var vs let) and data types
0:11 So the first way to do a Hello World to the console is to use console.log. Second way, we can do it in the browser is to use the built in alert.
0:30 And that gives us a nice pop up. To define a variable you can use var. But var is a bit outdated and these days it's best practice to use let.
0:47 This creates it's own scope and we'll see that in a bit. Let's rename it something else.
1:27 Okay, for example set an min age for driving at 18 and now I can not set this to another value. Because it's defined as a constant.
1:58 but now best practice is to use let and constants are defined with const. And we saw that one advantage of let is that you can not redefine a variable
2:09 and a constant can not be assigned another value. Var vs let. Let was introduced with ECMAScript 2015 let variables are Blocked Scope.
2:24 As we know from the Zen of Python name spaces are a good idea and that's exactly what's going on here because if you give a variable scope
2:34 then it's more difficult that variables take on values that you wouldn't expect. And here we see a practical example where with the old style, var
2:46 the variable will still be available outside of the block. And block I define as whatever goes into curvy braces. However with let the variables scoped
2:57 inside of this block and if you try to reference it outside of that block you get a reference error and that's way safer you can read more about that
3:06 on Mozilla's developer documentation. I want to introduce this early on in the lesson because it's often that you define a variable
3:31 It works pretty much as you would expect. We're all familiar with boolean from Python the only thing that like cause confusion
3:39 is null and undefined, where Python generally has None. The more options you have the more likely it's that you'll make a mistake.
3:49 Another tricky thing is one type for numbers which is number. And Python has ins and close which usually leads to less mistakes.
3:58 String you already know from Python str. And symbol is a new data type I have not found a use case yet so it's the youngest cub of this chapter.
4:16 and I will have an example latter in this lesson. But there's much more to it you can actually use them to add methods and behavior.
4:38 when you add different types together and that puts the responsibility on developer. A nice example is summing an int and a string.
4:48 In Python it will lead to a type error which probably is a good thing because Python doesn't really understand what you want to do.
5:02 So in this case you need to do a parseInt on the 37th string to get an integer result. So just keep that in mind that often times where Python crashes