1 00:00:09,220 --> 00:00:15,070 Hey, everyone, let's pick up from where we left in the previous video, we were going to start talking 2 00:00:15,070 --> 00:00:17,320 about incremental operators. 3 00:00:17,620 --> 00:00:21,830 So sometimes we just want to add values to a variable. 4 00:00:22,120 --> 00:00:26,290 So as an example, I'm going to create a variable called sales. 5 00:00:26,650 --> 00:00:29,530 So sales equals 20, for example. 6 00:00:29,830 --> 00:00:32,290 And now let's say I just want to add five. 7 00:00:32,560 --> 00:00:39,250 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 8 00:00:39,250 --> 00:00:39,700 this. 9 00:00:39,940 --> 00:00:43,930 So sales equals sales, which is now 20. 10 00:00:44,190 --> 00:00:46,420 And now I'm going to add five. 11 00:00:47,200 --> 00:00:49,330 So by doing this, we're adding five. 12 00:00:49,600 --> 00:00:51,010 Every time we do this. 13 00:00:51,280 --> 00:00:57,940 But there's also an easier way of doing this without repeating the name of the variable so we could 14 00:00:57,940 --> 00:00:59,320 write it like sales. 15 00:00:59,500 --> 00:01:06,370 Then use the incremental operator, which is plus equal and then five. 16 00:01:06,760 --> 00:01:09,440 And this is going to produce the same result. 17 00:01:09,700 --> 00:01:12,880 But this time we didn't have to repeat the name of the variable. 18 00:01:13,240 --> 00:01:16,240 But it's essentially the same thing that we wrote here. 19 00:01:16,450 --> 00:01:21,460 So the same way we can also use the minus equal. 20 00:01:21,850 --> 00:01:25,480 So now we are decreasing the value of the variable. 21 00:01:25,780 --> 00:01:32,050 And one cool thing about this incremental operator is that we can use it with strings. 22 00:01:32,380 --> 00:01:34,660 So let me just clear this. 23 00:01:35,430 --> 00:01:37,990 You fi have a variable called. 24 00:01:39,020 --> 00:01:43,290 First name or maybe the chooser like this. 25 00:01:43,360 --> 00:01:43,790 Name. 26 00:01:48,420 --> 00:01:50,030 Now, I have my name now. 27 00:01:50,490 --> 00:01:54,960 I can increment this variable by doing like this, so name. 28 00:01:57,160 --> 00:01:57,970 Plus equals. 29 00:01:58,210 --> 00:02:01,330 Now I'm going to add an empty space. 30 00:02:02,290 --> 00:02:03,990 Now I'm going to do it again. 31 00:02:04,570 --> 00:02:12,260 But this time I'm going to add my last name so we can keep doing this to add something to strings. 32 00:02:12,700 --> 00:02:14,590 So I just wanted to show you this. 33 00:02:14,920 --> 00:02:17,650 Now let's talk about type conversions. 34 00:02:17,920 --> 00:02:20,530 Sometimes we will have to do this. 35 00:02:24,030 --> 00:02:30,630 So in this example, let's say we received numbers as strings, this is very common sense signs. 36 00:02:30,650 --> 00:02:38,090 We're getting data from external sources and they just come as strings when we get data from inputs. 37 00:02:38,370 --> 00:02:40,620 This is also likely to happen. 38 00:02:40,920 --> 00:02:44,280 So when we have this that we just copy this. 39 00:02:45,670 --> 00:02:49,210 And pasted at the console like this. 40 00:02:49,780 --> 00:02:51,940 So now if I try to do first. 41 00:02:53,930 --> 00:02:54,600 No. 42 00:02:55,020 --> 00:02:55,860 Plus. 43 00:02:58,980 --> 00:03:00,150 Second number. 44 00:03:01,880 --> 00:03:05,030 What's happening here is that we have two strings. 45 00:03:05,270 --> 00:03:11,930 So what JavaScript does with the plus sign on strings is concatenation. 46 00:03:12,230 --> 00:03:14,480 So we're not making any sum here. 47 00:03:14,750 --> 00:03:19,370 We are just getting twenty one and concatenating it with four. 48 00:03:19,460 --> 00:03:20,900 These are strings. 49 00:03:21,590 --> 00:03:27,830 So in order to make this calculation with these kind of numbers, first, we need to convert them. 50 00:03:28,220 --> 00:03:32,660 So for that we can use the pass and or pass float. 51 00:03:33,140 --> 00:03:37,760 If you know you have only integer numbers you can just use the pass. 52 00:03:37,880 --> 00:03:44,960 And so repeating the operation instead of doing directly like this, I'm just going to use the. 53 00:03:46,130 --> 00:03:46,820 Boris. 54 00:03:48,170 --> 00:03:48,650 Int. 55 00:03:51,560 --> 00:03:54,140 So applying this to the first number. 56 00:03:55,160 --> 00:03:57,450 And the same thing for the second number. 57 00:03:57,560 --> 00:03:58,550 So pass. 58 00:04:00,660 --> 00:04:01,170 Int. 59 00:04:03,690 --> 00:04:10,560 So now we have the correct some because before doing the calculation, we are converting these strings 60 00:04:10,560 --> 00:04:11,430 to numbers. 61 00:04:11,700 --> 00:04:14,250 So the opposite is also true. 62 00:04:14,670 --> 00:04:21,220 So if you have an year of birth, for example, and this is a number and you just want to concatenate 63 00:04:21,220 --> 00:04:25,200 it with a string, you can use the two string method. 64 00:04:25,470 --> 00:04:27,540 So, again, this is a bit different. 65 00:04:27,870 --> 00:04:29,550 This could be a bit confusing. 66 00:04:29,760 --> 00:04:36,510 So in the first example, you're just right, pass it and put the variable name inside and to do the 67 00:04:36,510 --> 00:04:37,110 opposite. 68 00:04:37,140 --> 00:04:41,010 You just put the variable first and then dot to string. 69 00:04:41,220 --> 00:04:41,670 I know. 70 00:04:41,670 --> 00:04:42,960 I know this is confusing. 71 00:04:42,960 --> 00:04:45,510 Some people just hate JavaScript because of this. 72 00:04:45,540 --> 00:04:47,870 But don't worry about this now. 73 00:04:47,880 --> 00:04:51,660 This is just details, to be honest. 74 00:04:51,720 --> 00:04:54,090 I don't even memorize all these Fang's. 75 00:04:54,090 --> 00:04:59,340 I don't take space on my brain just to memorize that in case of string to integer. 76 00:04:59,370 --> 00:05:05,250 I have to do it like this when it's the opposite, when it's integer to string, I have to do it like 77 00:05:05,250 --> 00:05:11,810 this any anytime I want to confirm this, I have Google right in front of me so I can just type J. 78 00:05:11,900 --> 00:05:16,170 S string to integer and I will have the answer. 79 00:05:16,530 --> 00:05:18,150 So don't worry about this. 80 00:05:18,390 --> 00:05:23,220 If you know how to search for what you're trying to do, you will always have answers. 81 00:05:23,430 --> 00:05:29,190 Now, since we are talking about type conversions, just one thing to pay attention, you should always 82 00:05:29,190 --> 00:05:35,490 keep an eye on the type of your variables, because many times you won't notice that they are with the 83 00:05:35,490 --> 00:05:37,320 wrong types like this. 84 00:05:37,620 --> 00:05:39,180 Maybe we received the number. 85 00:05:39,330 --> 00:05:40,710 We do the calculation. 86 00:05:40,950 --> 00:05:46,860 We have an answer here and we think this is working, but we need to pay attention to see that. 87 00:05:46,890 --> 00:05:50,030 Oh, no, actually, this is not the correct sum. 88 00:05:50,160 --> 00:05:54,150 So always, always keep an eye on the types of your variables. 89 00:05:54,510 --> 00:05:54,830 All right. 90 00:05:54,840 --> 00:05:56,760 So now we are ready to move on. 91 00:05:56,820 --> 00:06:00,470 We're just going to talk quickly about two data types. 92 00:06:00,480 --> 00:06:03,990 So booleans and then no and undefined. 93 00:06:04,290 --> 00:06:12,180 And then we will do our first list of exercises where you were going to apply everything you learned 94 00:06:12,390 --> 00:06:13,120 so far. 95 00:06:13,380 --> 00:06:14,940 So I'll see you in the next video.