Teaching my 40 year old student with no experience programming | Operators

Phil Choi teaches JavaScript operators to a 40-year-old beginner. He covers arithmetic, string concatenation, increment/decrement, assignment operators, and the difference between == and === for comparisons. The session includes console.log exercises and debugging tips for reading code line-by-line.
Chapters
Do you have any questions after operators, by the way?
Not really, but it seemed pretty simple. I know it gets complicated or it will get more complicated.
If you think it's going to get complicated, it will get complicated. Everything's going to be a breeze. That's how I it's going to be.
A breeze, then it's going to be a breeze.
So now you have some tools in your belt, right? You have console log, you have logging, you have variables and you have data like strings and booleans and numbers type up. Let's go into operators. So operators in JavaScript help us work with data. They'll be used in many ways. Adding numbers, we just talked about that. Like minusing numbers, subtracting numbers, multiplying numbers, concatenating strings. So that word sounds crazy, but it's just if you have two strings, it'll just add those strings together. So if you say hello plus goodbye, it'll just say hello goodbye and comparing values. So that's like earlier when we put three plus four equals and does it equal seven? Do you know the alligators, like which side the alligator eats less than or greater than?
Yeah, yeah, yeah.
That's how I think about it.
It was a shark, right? It was a shark in California.
It was an alligator.
It's alligator.
Yeah. Because we were so afraid of sharks.
Oh, I see, I see.
If you go back to the readme and you go under the operators, you're going to see addition is a plus, an increment is a plus plus. You see that?
Yeah.
So plus plus means just one up.
Is it always going to be plus.
One or if it's plus plus. So you could. So there's other ways where you can take plus equals five plus plus is always just increment. One decrement is minus minus which is just decrement at one and then assignment is the equal sign which earlier we learned the variable the initializer text with no spaces and then equals and then whatever data you need to be comparison. We just talked about it. So it's the 2/2 sign is kind of like a soft equals. The triple equal sign is like a hard equals. So one equals true. So that's true. That's false. So this is like a soft compare my opinion. But then like actually one if we were really to look is not true because they're different data types. Like just like this would be true. Right. One equals. Equals one would be true. Right. I don't think we need to go into it further because I think we can talk about it for A long time. But in my code to write clean code, I think you just always want to use the three equal signs.
Okay.
I always use the exclamation point and then equals, equals. This is like, if it doesn't equal, it'll be like true. So like one doesn't equal two, that equals true, right? Because it does. This is a true statement. One does not equal two. But if we put one equals two, this is a false statement. We can make a variable and increment it. I'll do this one. So we can say let I equals zero, I plus plus. And if we console log I, what do you think it's going to log?
He said it increments it, so it's one.
So let's try it out.
That increment is only going to happen just that one time.
That one time the script is run.
Okay. Okay.
So if we did I + again, what do you think is going to happen then?
Two. Right. Because now it's run the first time, one, second time, two.
Exactly. So while this script is running, it'll do that. So it gets reset when the script is done running. Right. So earlier I think I said, like, you can do I plus equals two. So this is how you jump from jump two. So what do you think it's gonna be now?
So we end up 2 now plus 2. 4. Really checking my math here.
You really have to think because, like, when I think about programming. Right. You do a lot of things kind of like automatically. Right? Right. Like walking, you don't really think about your knee moving, you lifting your leg. It's just automatic. But in computers, you really have to break it down and be like, this computer doesn't know how to do anything and I have to give it instructions down to like exactly, you know, very obvious things like this equaling four. But you know what I mean? Like taking it down and like being able to read the code. Like line, okay. Line 13 is. Starts at zero. Okay. Then on line 15, increments by one. Okay. It's one. Okay. On line 17, it grins again. Okay, now it's two. Okay. On line 19, it adds two. Okay, four. You know what I mean?
Plus equals means we're still doing an increment, but now we're changing. Instead of it just being the one we want, we're modifying the increment amount with that plus equals exactly. Okay.
Okay. So if I run it now, it should go four, right?
Yep.
That's cool. So can you just make like three incrementing statements and log them and do it on a number one exercise one.
So I'm gonna say. All right, I think that's it. I don't know if that strings right or not.
No, it's correct.
Okay.
But I like to put a space so it's a little bit more.
Okay.
Yeah. And why don't you run the code real quick?
So no operator js.
Okay, 10. Okay, can you explain the code to me from line 13 to 16?
All right, so we have let A equals 5. So A is 5 on line 13. On line 14, we do an increment with A plus plus, which is going to give it a plus one to A. It's going to reassign it to the number or to the value 6. And then we again do the same thing with line 15. And so it gives us the number 7. And then now on line 16, we have A, which is 7, and we increment it by 3. And then at that point, A equals 10. And then on line 17, we're console logging and checking to see if my math is right. So.
Hey. Amazing. Amazing. This is. I think it's just, like, good to go through those exercises to kind of, like, think about every single small step. Because when you're debugging the code, you might see a big block of code, and you're like, okay, I expected to return this, but then you really have to go back and read it line by line and understand it.
And so if I really wanted to check my math, like, at each spot, like, instead of explaining all of it, would I be doing console log after every single one of those?
Like, yeah, here, I'll just. I'll give you an example. So you run this code three times, right? So what if I did something like this? Like 4 let I equals 0, I. I wanted to run three times, I'll increment I. Then I'll say let. So I have the A. And then I'll say if. If I equals one or zero. So that's. I, I want to increment the A plus plus else. If I equals one, I want to increment one and then else. So that's on the final try. I want to do it here. I mean, this is very. You wouldn't write code like this, but this is just an example of. So actually earlier I said A equals 0, I equals 1. So you could actually say people will write code like this and you'll have to debug it. Right. And it'll be hard because then you'll have to understand because someone could write, like, you could make this easy code into this. So what. What I'm saying is I'm. Hey, I'm looping through I is 0 while I is less than 3. 3, I want to increment my I and then I'll say, hey, if I. If I is false or if I is zero, I want to increment one. Okay. And then it'll go back and it'll be done there. I will become 1 and then else. If I equals 1, then I want to increment 1 and then it's less than 3. Is I 0? No. Is I 1? No. Okay, then we'll go into else and it'll be 3 and we'll add 3, and then it'll go back. I will equal 3. Is 3 less than 3? No. And then it'll be over. So what do you think the output of A would be here?
Oh, man, I haven't got you the for loop yet.
So just, I want to show, like, how complicated the code, like your reading could be when just this simple. It is just this code is in a for loop. So in the end It'll still be 10.
That was not my answer.
It'll still be 10.
Yeah, it's just.
It's complicated for no reason. Right.
Okay.
Yeah, yeah. That.
I don't know. I don't fully understand what's going on there, and I don't know how you got 10.
We'll learn it in for loops. We'll learn about for loops today. Just. You don't want to write code like this. This is. This is not. Let's get through these four, four exercises real quick. Make two variables that are numbers and add them together. So why don't you just put in a variable then cons Z or something.
Ah, so then Z will equal x plus Y.
Exactly.
And.
But you need to initialize the Z.
Because it's my first time using it. Right. Okay, so then I'm going to console log D. C equals C. All right.
And I would just turn all these into cons, because you're not reassigning any of them. Can you do exercise number three?
All right, so make three variables and multiply by three. All right? Const E and multiply together seven. Const G equals 12. And then I'm going to go E. I have no idea what the math is on that.
70.
70 times 12. 700 and 714. Yeah, quick math.
All right, so let's try to run the code. All right. Oh, 800. I said it so confidently too. Now make two variables that are strings and concatenate them. So that's just adding two strings. So let's try that out.
And that's. I'm gonna do another constant. Abcdf G H I.
Good.
ABCDF G H, I, J. Hopefully everybody's good with the Alphabet. Vibes Console log I plus. Oh, how do I get the space in there?
You could either put the space after good like this. Or you can do. You can put a space like this.
Okay, so that's gonna. That's. That's my string right there. And I'm adding just a space.
Yeah, of.
I'm adding a string. That's a space.
Exactly.
Okay. No operator js.
Goodbye, good vibes.
There it is.
And maybe we could have even just. If you wanted the same result, you could have put a comma.
Oh, really?
Make two variables that are numbers and compare them. So compares are like the alligators or the sharks, like we said. And like the triple = cons k.
Equals 15, l l in my head, 20.
All right.
And then compare const m. Does k triple equals L? I don't know. I don't feel good about that one. No, it's good. I should get the boolean right because I'm using the triple equals. So I should get false.
Exactly.
15 doesn't equal 20.
So we got everything we expected, right? We try to use a shark, a greater than or a lesser than sign. And then why don't we try to make the statement true on line 38? Let's just modify it.
So then it's going to be. We want to get a true statement right. So then is K less than L? 15 is less than 20. We're going for true. We're going for true.
Amazing. Okay, great. Just one more thing. On all your logs, I want you to write a log underneath and tell me the data. Show me the data type the type of that it is. So you're going to do something like console.log type of a like this. And just on top of each of the logs so we can type out what kind of type it is on line 25.
Console log type of Z.
Why don't we do something like this, Shay? We do like IJ is like this and then you can just say type of ij and then from here we can just do IJ equals ij. Yeah, it's like the same pattern that you were doing with all the other ones. So I just wanted to kind of stick with the pattern you were doing. Okay, so we got number. That's a number that Z number H C string ij and a boolean for and also, whenever you're doing type of, it always gives you back. These things are always strings.
Like, have you used it before? As far as like. Like after you've done a type. Okay.
I just wanted you to know that the return of type of is a string.
Okay.
Do you have any questions after operators, by the way?
Not really, but it seemed pretty simple. I know. It gets complicated or it will get more complicated.
If you think it's going to get complicated, it will get complicated. Just everything's gonna be a breeze. That's how I it's gonna be a.
Breeze, then it's gonna be a breeze.
More from Phil

day in the life of a software engineer | 5 hour productivity | building my dev agency 🔥

day in the life of a software engineer | 3 hour productivity | coding my 6-figure community startup

day in the life of a software engineer | 5 hour productivity | coding our sns startup app LFG

day in the life of a software engineer | 5 hour productivity | creating apps that makes big money






