Hey, everyone, let's pick up from where we left in the previous video, we were going to start talking
about incremental operators.
So sometimes we just want to add values to a variable.
So as an example, I'm going to create a variable called sales.
So sales equals 20, for example.
And now let's say I just want to add five.
Let's say I'd just sold another item and I want to add it to the total sales so I could write it like
this.
So sales equals sales, which is now 20.
And now I'm going to add five.
So by doing this, we're adding five.
Every time we do this.
But there's also an easier way of doing this without repeating the name of the variable so we could
write it like sales.
Then use the incremental operator, which is plus equal and then five.
And this is going to produce the same result.
But this time we didn't have to repeat the name of the variable.
But it's essentially the same thing that we wrote here.
So the same way we can also use the minus equal.
So now we are decreasing the value of the variable.
And one cool thing about this incremental operator is that we can use it with strings.
So let me just clear this.
You fi have a variable called.
First name or maybe the chooser like this.
Name.
Now, I have my name now.
I can increment this variable by doing like this, so name.
Plus equals.
Now I'm going to add an empty space.
Now I'm going to do it again.
But this time I'm going to add my last name so we can keep doing this to add something to strings.
So I just wanted to show you this.
Now let's talk about type conversions.
Sometimes we will have to do this.
So in this example, let's say we received numbers as strings, this is very common sense signs.
We're getting data from external sources and they just come as strings when we get data from inputs.
This is also likely to happen.
So when we have this that we just copy this.
And pasted at the console like this.
So now if I try to do first.
No.
Plus.
Second number.
What's happening here is that we have two strings.
So what JavaScript does with the plus sign on strings is concatenation.
So we're not making any sum here.
We are just getting twenty one and concatenating it with four.
These are strings.
So in order to make this calculation with these kind of numbers, first, we need to convert them.
So for that we can use the pass and or pass float.
If you know you have only integer numbers you can just use the pass.
And so repeating the operation instead of doing directly like this, I'm just going to use the.
Boris.
Int.
So applying this to the first number.
And the same thing for the second number.
So pass.
Int.
So now we have the correct some because before doing the calculation, we are converting these strings
to numbers.
So the opposite is also true.
So if you have an year of birth, for example, and this is a number and you just want to concatenate
it with a string, you can use the two string method.
So, again, this is a bit different.
This could be a bit confusing.
So in the first example, you're just right, pass it and put the variable name inside and to do the
opposite.
You just put the variable first and then dot to string.
I know.
I know this is confusing.
Some people just hate JavaScript because of this.
But don't worry about this now.
This is just details, to be honest.
I don't even memorize all these Fang's.
I don't take space on my brain just to memorize that in case of string to integer.
I have to do it like this when it's the opposite, when it's integer to string, I have to do it like
this any anytime I want to confirm this, I have Google right in front of me so I can just type J.
S string to integer and I will have the answer.
So don't worry about this.
If you know how to search for what you're trying to do, you will always have answers.
Now, since we are talking about type conversions, just one thing to pay attention, you should always
keep an eye on the type of your variables, because many times you won't notice that they are with the
wrong types like this.
Maybe we received the number.
We do the calculation.
We have an answer here and we think this is working, but we need to pay attention to see that.
Oh, no, actually, this is not the correct sum.
So always, always keep an eye on the types of your variables.
All right.
So now we are ready to move on.
We're just going to talk quickly about two data types.
So booleans and then no and undefined.
And then we will do our first list of exercises where you were going to apply everything you learned
so far.
So I'll see you in the next video.