So now we're going to talk about JavaScript functions and JavaScript arrays. So functions use the function keyword, unlike Python, this would be like deaf in Python. So we basically say, function, and then give the name of the function, and then the parameters to the function, and then you have a curly brace to start the function, and then end the function. Move this over here, and then you have returned to return the resulting value and that return defines the return value that's going to be used in some expression. So you're cruising along, you're in the middle of an expression, you encounter a function, it calls the function, runs the call, and then the return value is what is the residual that's placed in that plus. So whatever that value is, in this case, it's going to add four and five, and end up with nine as the result in prod equals nine. So the functions other than that are like most programming languages, except when it comes to global variables. Most of the time, when you're working with a function, every variable that you define inside the function is local to that function. So if you use the same variable outside the function, now I'm doing this two lines away, but really often, this function is inside of a library and it doesn't even know what variables are being used outside of it. So by default, these two are the same. I'm not really familiar with a lot of other programming languages where the default is the that that's global variable if you don't make it worse. It depends on whether this global variable is defined before or after, too. In this case I'm defining the global variable before and I say nothing special about gl, and so it's global. I set it to 123, then I call this function and it sets it to 456, and when we come back from the function, it's 456. That's weird. It's just weird super global by default, which is not the way we usually like to run functions. So what we do, and it's really weird, there's no other programming language that makes you say don't be global. Most other programming languages, if they have a global capability, and not all of them do, they're like this is the weird one that's global and everything else is local. What you do is if you don't say it's local, it's going to be global. So the var keyword basically says it's local. This is a variable and it's local. So I can say var gl equals 456. That means that variable has no effect outside the function, i.e, the function lives in its own little silo, which is the way most functions usually work unless we explicitly bust out of the little silo. So in this case, if we do gl equals 123, then we call function check and we look at gl, even though inside a function, there's a gl that's 456, not the same gl, and so we get 123 when it's all said and done. So that's really quite nice. But you didn't put a lot of vars in and one of my biggest bugs when I write JavaScript is to forget to put the var in. So I now have been punished enough to know always put the var in so you get what you expect as a default in most other programming languages, that variables are defined inside of a function are local unless you're very explicitly doing otherwise. JavaScript has arrays. They look a lot like Python lists. So here we have an array that's three strings. JavaScript has an associative structure, but it's not an associative array and it's more like a dictionary, but it's not, it's an object. Objects can be many things, and we'll have a whole lecture on nothing but objects. But right now, they look like a dictionary. Key value pair. Key is name, value is chuck. Key is class, value is dj4e. So that when you print that out, away you go. Now, you can say a_0, which gives you X, which is that first element, and you can say b_"name." You can do that. Another way to say that is b.name. Those two syntaxes, and this confused the heck out of me when I was first learning JavaScript, those two syntaxes mean the same thing. They both are saying, look up an attribute of the object b that's named name. Again, they are the same thing, even though for every other language that you ever look at, you think those are very different creatures, but not so in JavaScript. It has to do with the fact that b is an object. It is an object. So objects are the associative structures, but they're even more powerful than associative arrays are in some languages, like directories. Linear arrays. You can make linear arrays. You can fill them up a couple of different ways. You can either fill them up. We start to make an array and we can push some elements in. I don't like the name push. I like append better. That would be what we would say if we were in Python, if this were a list. But it works. Push pushes onto the end. Normally, push means push onto the beginning. But in computer syntax, push usually means push down, not append. So I think Python has a JavaScript there where we say append in Python, we say push in JavaScript. Or we can just fill it up with the array_0 and array_1, and then we can fill up a nice linear array if we want. Remember, in JavaScript, arrays are arrays. They're not dictionaries. They are lists. Python has lists and dictionaries and JavaScript has arrays and objects. There's other syntaxes for making arrays. You can say array and then just have a list of things that make up the array, and you get an array, or you just use the constant from that square brackets, and this looks exactly like how we would do it in Python. So that works. So in that particular line, you can write Python and JavaScript if you so desire. Up next, we're going to talk about control structures.