So one of the important parts of any programming language is the operators and the expressions. And so these, of course, are very much like all C-based languages. We have our plus, minus, multiplication is asterisk, division is slash. Division, unlike Python2, is it creates floating point based on just like you might expect from a calculator. So if you take 9/2, you get 4.5. Modulo, which is an integer division that gives you back the remainder. And then there are these side effect operators like k++, which is the same as k = k + 1. So we get a -- and you can have these ++ or --, either in the back or in the front. You can also have side effect operators like j += 5, which is the same as j = j + 5. And again, these are contractions that we tend to avoid, unless, we have a reason to kind of make our syntax really dense. The comparison operators are very much like PHP and the C language. So we have, the big thing to remember is that there's an assignment statement, that's the =, and == is the question mark. So asking the question is j = 10? is double equal sign. And then, from that not equal flows, less than, less than, greater than, less than or equals, all are kind of straight forward. And there's two kinds of equality operators, one is the ==, which is effectively numeric equivalence or equivalence after type conversion. And then the ===, is comparison without type conversion. So if I put false into j, and we had the same thing in PHP, false into j. And let's say, is false numerically equal to 0? And the answer is yes. Is false identical to 0? And the answer is no, it is not, okay? And is false identical to false? Yes, it is. And there is also a not triple equals. And again, these are very PHP like. It's funny, I like these. I was probably going to do some programming in Java, the big language Java. And I didn't have these, and I'm like, Oh if it's false. But in Java, the equality is different because you don't do auto type conversion. And so in languages like PHP and JavaScript to do automatic type conversion, you have to have an equality test that stops the automatic type conversion, because this implies an automatic type conversion. In the language like Java, that's a strict type language. You can't have two types. You can't check the equality of two different types because just a syntax error. But in JavaScript, we have numeric equality and absolute equality, which is type and value. The logical operators are, again, straight from the C language. && is logical AND. So both sides must be true. true && true becomes true. OR, meaning either side, you know, true || false becomes true, because only either side has to be true. Greater than. Greater than and NOT, in logical expressions are as an !, like in C languages. If we're looking at that, that would be exactly as it is in C. And if we're looking at all of these things, they would be exactly the same as the C language and the Java language, except these things are, they're used in C like languages that don't have strict typing. Concatenation. PHP, I love the dot concatenation operator, but I accept the fact that it will never be in any other language except PHP. We use + to do concatenation. And then of course, it does string conversions automatically. It's not like Python where you've got to get the types exactly right. The + simply says: "Oh, I got a string and a number. Let's turn that number into a string so I concatenated it together." And so, x becomes the string 12. And so we concatenate "Hello 12 people". And like all languages, this doesn't add a space. And so these two spaces are explicitly put into the string so that they actually work. JavaScript is a loosely typed language. There's a video that perhaps, I'll put a reference elsewhere to, that's kind of funny, about how adding things together, different types, it's all very consistent, but it's not something that a beginner would predict. And so in this case, let's just take a look at some silly things. 123 + 10. Well, is that a numeric? Well, in PHP that would be deterministic because + is a numeric operator, but + is not a numeric operator. It might be concatenation, it might be a numeric. In this case, it sees it as concatenation. And so we get a string "12310". But multiplication is a numeric operator. So, "123" times 1 is the number 123 and then you add 10 to it and that's 133. And this is different than PHP, the string "fred" multiplied by 1 that's a numeric, no numeric operation. And instead of pretending that fred is zero like PHP would do because PHP is very loosely typed, JavaScript has this notion of Not a Number (NaN). And so, when it looks at "fred" and tries to convert "fred" into a number, it goes that's not a number. And then not a number * 1 is NaN. And if you take x which then ends up being NaN and then + 1 to it, NaN + 1 is still NaN. So that NaN is kind of a sticky thing. And it just kind of fun to look in some UI and blah blah blah blah blah NaN. And it's always, you know, uppercase and lowercase and and you're like: "Oh they did some conversion." They're just some calculation in JavaScript and it didn't work out so well. And so you see NaN in all kinds of user interfaces and you know that they're doing math in JavaScript and they got some kind of a bad value divided by zero or took an undefined thing and multiply that by something else. And then they printed it out in the document object model and it came out as a NaN. That's kind of a running joke of JavaScript is that NaNs. So NaN, like I said, is sticky. You can check to see if a variable is a NaN, like isNaN() is a function that returns true or false. Dividing by zero gives you Infinity. And these are actually, so JavaScript seems weird in this case, but in a way JavaScript is, sort of, more right. So dividing by zero shouldn't be, you know, an error just Infinity. So that's what it is mathematically. And there's situations that are mathematically NaN. And so, there is kind of an underlying official standard for how numbers are supposed to function, and JavaScript is probably closer to those than other languages like PHP. So, even though we make fun of NaN all the time, it's probably a more responsible numeric implementation than some other systems might have. There is a typeof operator that can tell you whether something is a string or an integer or whatever. And it returns itself a string, which means that you can put that in 'if' statement. You can say if typeof variable == "string" and it will tell you something, and that's a common thing that we do. Functions are an important part of any programming language. There's lots about JavaScript functions that are exactly as you might expect. There's a function, this again very C-like function, name function arguments to the function. The arguments by default are passed by value not passed by reference, and then you can have a return value and that all sort of works the exact way that you would expect in any other programming language. So, that part's pretty straightforward. But the weird part, someday I'd like to know why. But the weird part is, one of the things that I always talk about when I talk about functions is how they are like isolated by default from the outside world. The only thing that we touch are the parameters that go in and the return value that comes out. And the stuff that goes on in the function, generally, does not sort of bleed out into the outside world by default. Not true in JavaScript, super not true in JavaScript, freakishly not true in JavaScript. So in JavaScript, if there is a variable, you're coming down and this is done in sequence, the fact that this gl is before the function actually matters. Because it's sort of evaluating this in order. And it looks at this thing and says: "Oh, you didn't tell me that this was local and there is a variable that's global, so I'll just make these two things the same." So at this point, we have gl out here. It ends up with 123 and then this code runs, and it's the same gl, and so that changes this to 456. And so, when we run the check function, it changes to 456, and then we print it out, and out comes 456. I think that's like a not a very good feature by default but it is and we can't change it. So one of the things you see in JavaScript, all responsible JavaScript programmers have used var, var, var, var, var. Like, don't forget to use the var. So what var says is, var, effectively, draws what I wish was default to say this is a local variable, even though there is a variable globally of the same name. This gl does not, sort of, smear out or percolate out beyond its boundaries, somehow. And so in this case, there are two gls. There is a gl in here and a gl out here. This one gets 123 in it. The code runs. This one gives 456 in it. Then the code comes back and then the global one is unchanged. And so, that's really the way you want it. So, you think to yourself, why do I have to keep doing this? You've got to put var in. I have written a lot of JavaScript where the mistake was like, why isn't this working? Well, it's because I didn't have the var. I'm like, put the var in. So, just get used to it, it's a little weird, you have to explicitly mark variables within functions as if they are local. So, you have to explicitly say it, it's not like any other, well at least most other commonly used program languages don't do that. So next, we'll talk about arrays. Arrays and objects are always sort of the fun part of any programming language.