1 00:00:09,080 --> 00:00:15,650 Hey, everyone, in the previous video, we learned about variables, we just created our first variables 2 00:00:15,650 --> 00:00:17,720 and assign some values to it. 3 00:00:18,230 --> 00:00:22,850 Now we are going to learn which data types can be assigned to our variables. 4 00:00:23,180 --> 00:00:26,540 So the most basic ones are strings and numbers. 5 00:00:26,870 --> 00:00:33,890 So I don't have to tell you what a number is, but a string is just a piece of text like John or I'm 6 00:00:33,890 --> 00:00:37,480 34 years old or the address of a website. 7 00:00:38,030 --> 00:00:40,790 These are all examples of strings. 8 00:00:41,000 --> 00:00:44,030 And those are the most common data types. 9 00:00:44,360 --> 00:00:52,040 But we also have some very important data types that we are going to talk more about them like booleans, 10 00:00:52,370 --> 00:00:53,300 undefined. 11 00:00:53,720 --> 00:00:55,670 We have a race object. 12 00:00:56,180 --> 00:00:57,890 Those are all very important. 13 00:00:58,160 --> 00:01:01,970 And the cool thing is that this is not only apply to JavaScript. 14 00:01:02,420 --> 00:01:08,300 Most programming languages, they have the same data types with some small differences, but it's pretty 15 00:01:08,300 --> 00:01:09,140 much the same. 16 00:01:09,410 --> 00:01:16,460 So after learning this, it's going to be very, very easy for you to learn other programming languages. 17 00:01:16,550 --> 00:01:17,240 If you want. 18 00:01:18,050 --> 00:01:21,790 So first, how can we know what's the data type of a variable? 19 00:01:21,860 --> 00:01:23,540 So let's create one now. 20 00:01:23,810 --> 00:01:24,830 Let's say var. 21 00:01:26,560 --> 00:01:27,430 First name. 22 00:01:31,370 --> 00:01:32,420 Let's use John. 23 00:01:34,070 --> 00:01:37,160 I'm going to talk about these quotation marks in a minute. 24 00:01:37,190 --> 00:01:38,810 Let me just show you something. 25 00:01:39,020 --> 00:01:40,970 So I've just created this variable. 26 00:01:41,150 --> 00:01:45,140 If we try to access it, we can see that the name is here. 27 00:01:45,380 --> 00:01:48,680 It has been correctly assigned to our variable. 28 00:01:49,010 --> 00:01:52,190 And now if we use the type of operator. 29 00:01:53,250 --> 00:01:54,660 With the first name. 30 00:01:58,570 --> 00:02:01,590 We can see that the console is returning strings. 31 00:02:01,690 --> 00:02:06,700 So this is the data type of our first name variable. 32 00:02:07,060 --> 00:02:08,610 Now let's try a number. 33 00:02:08,830 --> 00:02:11,440 I'm just going to create one called age. 34 00:02:12,340 --> 00:02:14,030 I'm going to assign a number. 35 00:02:14,050 --> 00:02:16,510 So now I'm not using quotation marks. 36 00:02:17,820 --> 00:02:21,150 Now doing the same thing type of age. 37 00:02:22,540 --> 00:02:24,290 Is returning a number. 38 00:02:24,700 --> 00:02:27,520 Now let's talk more in depth about strings. 39 00:02:27,580 --> 00:02:34,770 Let me just refresh the page so I can clean this so we know that the text values are called strings. 40 00:02:34,780 --> 00:02:37,540 So it just tried a name of a person. 41 00:02:37,540 --> 00:02:39,610 We could we could type a text. 42 00:02:39,970 --> 00:02:44,830 But actually, the best definition for a string is a sequence of characters. 43 00:02:45,100 --> 00:02:48,730 So any string is just a sequence of characters. 44 00:02:49,570 --> 00:02:53,920 The way we identify a string is by using quotation marks. 45 00:02:54,130 --> 00:02:56,470 So this is why we've been using it so far. 46 00:02:56,710 --> 00:03:03,370 When we send the message to the council, it has to be inside quotation marks because this is a symbol 47 00:03:03,460 --> 00:03:04,900 of a string. 48 00:03:05,230 --> 00:03:10,990 We can use either double quotation marks like this or single quotation marks. 49 00:03:11,290 --> 00:03:12,940 Both are valid. 50 00:03:13,210 --> 00:03:14,780 You just have to keep consistent. 51 00:03:14,800 --> 00:03:18,010 You can start with a single and finish with a double. 52 00:03:18,040 --> 00:03:22,840 This is going to return an error, but you can choose either one or the other. 53 00:03:23,020 --> 00:03:26,260 So here we have a few more examples of strings. 54 00:03:26,440 --> 00:03:29,500 So a passport number would be a string. 55 00:03:29,830 --> 00:03:31,960 Here we have a phone number. 56 00:03:32,500 --> 00:03:33,710 Although this is only. 57 00:03:33,720 --> 00:03:34,180 No. 58 00:03:34,750 --> 00:03:36,820 Why are we using strings? 59 00:03:37,210 --> 00:03:43,240 This is because we only use numbers when we are likely to use them for calculations. 60 00:03:43,480 --> 00:03:46,120 So let's say we have the age of a person. 61 00:03:46,480 --> 00:03:51,160 We might use it to get the average age of a group of people. 62 00:03:51,250 --> 00:03:53,320 We might use it to increment. 63 00:03:53,500 --> 00:03:58,240 When the person gets older, we might use it to find their year of birth. 64 00:03:58,300 --> 00:04:03,430 So there are many types of calculations that we can do with the age of a person. 65 00:04:03,670 --> 00:04:05,650 But there is no calculation we can do. 66 00:04:05,680 --> 00:04:07,120 We have a phone number. 67 00:04:07,390 --> 00:04:10,090 So this is okay to store it as a string. 68 00:04:10,270 --> 00:04:13,690 We also have the email of a person and a longer tax. 69 00:04:13,720 --> 00:04:16,540 These are all examples of strings. 70 00:04:17,020 --> 00:04:20,680 Now let's see a few operations that we can do with strings. 71 00:04:20,740 --> 00:04:23,440 So the first one is going to be concatenation. 72 00:04:23,470 --> 00:04:27,430 This is probably the most common thing that we do with strings. 73 00:04:27,880 --> 00:04:30,880 I already showed you this in the previous video. 74 00:04:31,270 --> 00:04:39,250 So to do this, we just use the plus sign and how this JavaScript know that it should do concatenation 75 00:04:39,250 --> 00:04:40,350 and not a sum. 76 00:04:40,690 --> 00:04:43,570 This is because we are using quotation marks. 77 00:04:43,750 --> 00:04:51,280 So JavaScript knows that this is a string and JavaScript knows that the plus sign is used for concatenation 78 00:04:51,280 --> 00:04:52,480 with strings. 79 00:04:52,720 --> 00:04:56,410 If we had numbers, we would have the some of the numbers. 80 00:04:56,680 --> 00:05:05,800 So if I type something like my first name and then use the plus sign and then just use an empty space. 81 00:05:05,890 --> 00:05:07,870 And now the plus sign again. 82 00:05:07,900 --> 00:05:15,310 And my last name, if I do this, the result is going to be a string formed by this concatenation. 83 00:05:15,610 --> 00:05:19,090 As you can see in the example, we can also do it inside a variable. 84 00:05:19,100 --> 00:05:21,730 So we just assign this value to the variable. 85 00:05:22,060 --> 00:05:24,730 And in the end, we will have the full name. 86 00:05:25,000 --> 00:05:29,860 Another interesting thing we can do with strings is getting the length and the index. 87 00:05:30,100 --> 00:05:31,990 So let's create a new variable here. 88 00:05:31,990 --> 00:05:32,830 So var. 89 00:05:35,630 --> 00:05:37,480 First name equals John. 90 00:05:37,520 --> 00:05:39,980 Now we have a string inside this variable. 91 00:05:40,220 --> 00:05:44,060 And if we do first name dot lenth. 92 00:05:45,360 --> 00:05:50,490 It's returning for which is the number of characters inside this string. 93 00:05:50,730 --> 00:05:58,320 So in this sequence of characters, we have four characters total in each of these characters have their 94 00:05:58,320 --> 00:05:59,580 own index. 95 00:05:59,940 --> 00:06:02,400 So if I do it like first name. 96 00:06:03,450 --> 00:06:06,780 And then I use braces like this or brackets. 97 00:06:07,500 --> 00:06:10,770 And inside it, I can pass an index. 98 00:06:11,070 --> 00:06:14,640 So Index says they start from zero. 99 00:06:14,820 --> 00:06:18,840 So zero is the first character of a sequence. 100 00:06:18,960 --> 00:06:20,720 So this is index zero. 101 00:06:21,090 --> 00:06:22,590 This is index one. 102 00:06:22,950 --> 00:06:24,210 Index two. 103 00:06:24,510 --> 00:06:26,280 And index three. 104 00:06:26,520 --> 00:06:29,520 We can get each of these characters if we want. 105 00:06:29,580 --> 00:06:33,300 So if we do it like this, it's going to return J. 106 00:06:33,690 --> 00:06:36,780 Which is the first character of this string. 107 00:06:37,110 --> 00:06:39,170 So now it seems a bit silly. 108 00:06:39,180 --> 00:06:41,340 It seems a bit useless to do this. 109 00:06:41,340 --> 00:06:46,620 But trust me, we are going to use this a lot when working with strings. 110 00:06:46,980 --> 00:06:52,190 Now, just one more thing that I want to show you about strings is string replace. 111 00:06:52,470 --> 00:06:54,810 This is also very commonly used. 112 00:06:55,140 --> 00:06:58,570 So I'm going to create a variable called You are Real. 113 00:06:59,310 --> 00:07:05,730 And I'm going to use this string, which is the address of a website, you demis Web site. 114 00:07:06,790 --> 00:07:08,090 So let's say I have this. 115 00:07:08,420 --> 00:07:16,550 This is important with the htp ass because we can use it for a link, for example, but maybe we don't 116 00:07:16,550 --> 00:07:23,520 want to show the full address if we want to send this address to an element, to a link elements. 117 00:07:23,600 --> 00:07:28,520 Maybe we will send the complete address to the age Rahaf attribute. 118 00:07:28,700 --> 00:07:30,990 So we go to the correct destination. 119 00:07:31,190 --> 00:07:35,870 But inside the text of the link, maybe we just want to show it from here. 120 00:07:36,080 --> 00:07:42,710 So if you want to remove part of a string, it's really easy to do with the replace method. 121 00:07:43,100 --> 00:07:46,550 So I'm going to use my variable, which is a string. 122 00:07:46,970 --> 00:07:49,370 Now I'm going to use the replace method. 123 00:07:49,790 --> 00:07:55,520 So using a dot to call a method, the name of this method is replace. 124 00:07:56,350 --> 00:07:58,160 And the way it works is. 125 00:07:59,250 --> 00:08:04,080 Inside parentheses, first, we are going to inform the text. 126 00:08:04,200 --> 00:08:05,760 We are looking to replace. 127 00:08:06,030 --> 00:08:12,600 So in this case is HTP, TTP s Colline forward slash, forward slash. 128 00:08:13,050 --> 00:08:15,650 Actually, I'm missing an ass here and now. 129 00:08:16,630 --> 00:08:25,840 We need to inform what is going to replace this text so we can use anything we want, like an empty 130 00:08:25,840 --> 00:08:26,410 string. 131 00:08:26,710 --> 00:08:33,550 So when I press enter, we can see that now we just remove the age TTP s from our string. 132 00:08:33,850 --> 00:08:36,860 Those are only a few examples that I wanted to show you. 133 00:08:36,880 --> 00:08:41,880 If you want to learn more, you can just click here and go to W3 schools. 134 00:08:41,880 --> 00:08:47,440 You are going to find many, many string methods you can use in JavaScript. 135 00:08:47,920 --> 00:08:51,250 So that was all I wanted to talk about strings for the moment. 136 00:08:51,490 --> 00:08:53,920 Like I said, don't worry too much. 137 00:08:54,340 --> 00:08:58,150 Let's just do this step by step, little by little. 138 00:08:58,440 --> 00:09:02,560 We're going to learn a little bit about each of the data types. 139 00:09:02,580 --> 00:09:04,750 Then we are going to have an exercise. 140 00:09:04,750 --> 00:09:10,450 And by the end of this, you will see that you will be very comfortable working with the different data 141 00:09:10,450 --> 00:09:10,900 types. 142 00:09:11,230 --> 00:09:14,950 So I'll see you in the next video so we can start talking about numbers.