0:03 in this lecture we going to talk about
0:05 some of the code data types in
0:08 typescript basically in this lecture we
0:10 will talk about string data type number
0:13 data type and Boolean data type so all
0:16 the values which we assign to a variable
0:18 it has a certain type for example a
0:20 value assigned to a variable can be a
0:23 string value a number value a Boolean
0:26 value an object an array Etc so all
0:29 these are data types in typescript and
0:32 the main data types are string number
0:34 and Boolean because these are the three
0:37 data types which is used extensively in
0:39 any programming language apart from
0:41 these three data types we also have
0:43 other types of data types which we will
0:45 talk about in our coming lectures but in
0:47 this lecture let's learn about string
0:49 data type number data type and Boolean
0:50 data type in
0:53 typescript so I'll comment this code
0:56 from our previous
1:01 lecture and let me copy this heading
1:04 here so now we are going to talk about
1:06 data types in
1:09 typescript and this is lecture
1:11 four all
1:14 right so first we are going to talk
1:17 about string data
1:21 type now a string is basically a
1:23 sequence of character and in types
1:26 script we can create a string by
1:28 wrapping some text within double codes
1:31 so string is nothing but a text value so
1:33 for example let's create a
1:36 variable and I'll create this variable
1:38 using const keyword and let's call this variable
1:39 variable
1:42 ST1 now to this we want to assign a text
1:46 value a text value is basically a string
1:49 type so in order to create a string in
1:51 typescript just like in JavaScript we
1:53 can create it using single codes like
1:56 this so here we can say this is a string
2:00 created using single codes
2:02 okay so we can create a string using
2:05 single codes in the same way we can also
2:08 create a string using double codes so
2:11 here we can say this is a string created
2:14 using double
2:17 codes okay and there is practically no
2:20 difference when we create a string using
2:21 single quotes or double
2:25 quotes then we can also create a string
2:27 using back text so let's create a
2:30 variable let's call it st3
2:38 variable so this is also
2:42 possible now when we use backticks we
2:44 have several benefits so for example if
2:47 I try to create a string using single
2:48 quotes or double quotes in multiple
2:52 lines like this here we will get an
2:56 error okay so we cannot create strings
2:58 in multiple lines using single Cotes or
3:01 double quotes but with backtick we are
3:03 not going to get that
3:06 error okay it is still being treated as
3:09 a string value so using back Tex we can
3:12 write our string in multiple
3:16 lines and this is the benefit of using
3:19 backtick then another benefit is if we
3:23 want we can also use template literal
3:25 syntax when we are using btic so for
3:27 example inside this string if I want to
3:30 use a variable somewhere I can simply
3:33 use template literal syntax like this
3:35 and in here I can specify a variable
3:36 name for example we have this sdr1
3:39 variable I can use it like this and we
3:42 will not get any error and in place of
3:44 this the value of St str1 will be
3:48 rendered so all these texts will be same
3:51 but in place of this template syntax the
3:53 value of SDR one variable will be
3:56 rendered so this also we can do when we
3:59 are using back Texs in order to create a
4:01 string but but that is not possible in
4:02 strings which we create using single
4:05 code or double code okay so here we
4:07 cannot do like
4:09 that and let's actually check that by
4:13 compiling this code so what I will do is
4:16 I'll open vs code built-in
4:21 terminal and here I want to use command prompt
4:23 prompt
4:26 okay let me clear the terminal here and
4:29 now we want to build we want to compile
4:31 this app. TS file so again to compile
4:35 app. TS file we can say TSC space app.
4:37 TS let's press
4:41 enter and here we do not have any error
4:43 let's check the Javascript
4:45 file all right we do not have any error
4:48 because we have not saved the file so it
4:51 has compiled the older code and that's
4:55 why in the app.js you will see the older
4:58 code so let's save this
5:02 file and let's compile this .ts
5:06 again and now let's see the JavaScript
5:09 code so here you can see that that
5:11 typescript code has been compiled to
5:19 this so here this template lit syntax it
5:21 will be rendered as a string it is not
5:24 going to replace this s str2 variable
5:25 with its value let's actually see that
5:28 let's refresh the page here and before
5:32 that let's close this app.js let's go
5:35 ahead and let's log
5:44 S3 let's save the changes let's compile
5:46 this app dots file
5:49 again it has been compiled and you can
5:53 see when we are logging S1 it says this
5:56 is a string created then we can see this
5:58 dollar s str2 instead of rendering the
6:00 value of this s Str 2 it is simply
6:03 rendering dollar Str str2 and when we
6:05 are using St str3 it says this is a
6:08 string created using back Tex and then
6:12 it is also logging the value of s str1
6:13 and it says this is a string created
6:16 using and in s str1 again this part is
6:19 not getting replaced with the value of
6:21 this Str str2 so that's what you will see
6:22 see
6:25 here okay so as you can see when we use
6:27 back text there we can use template it
6:29 syntax and we'll be able to use it properly
6:30 properly
6:32 but here we cannot use template L syntax
6:33 where we are using single Cotes or
6:37 double Cotes there it is going to give
6:40 us an unexpected result as you can see
6:43 here so this is how we create a string
6:47 in typescript again let me command this
6:52 code and now let's talk about number
6:55 type the number type represents both
6:57 integer and floating Point number in
7:00 typescript so just like in Javas script
7:02 we don't have a separate data type for
7:05 integer types or floating Point types we
7:07 have only one data type called number
7:09 which can store both integer values
7:11 floating Point numbers or any other type
7:14 of numeric value in typescript so in
7:17 order to create a number type what we do
7:18 is we create a variable let's call it
7:21 num and to that we can assign any
7:25 numeric value for example 12 like this
7:27 so now the data type of this num
7:31 variable you can see it is number in the
7:34 same way if I create another variable
7:37 let's say pi and to this I assign 3.14
7:39 so here I'm assigning a floating Point
7:41 number to this Pi variable and if I
7:44 check the data type of this Pi again you
7:47 will notice that its value is 3.14 but
7:49 we are not seeing the data type here
7:51 that's because it is a constant type but
7:53 if I use let keyword here and now if I
7:56 over over this Pi you can see that the
8:00 data type of this Pi is number but when
8:02 we use const at that time also the data
8:04 type is going to be Pi but since it is a
8:06 constant it is always going to have the
8:08 same value 3.14 we are not seeing the
8:11 data type now one very important point
8:13 you need to remember about the number
8:16 type in typescript or JavaScript is that
8:18 typescript numbers are always floating
8:21 Point numbers which simply means that
8:23 they always have decimal even if we
8:25 sometimes don't see it so for example
8:28 when we assigning this integer value 12
8:30 to this number value variable when it
8:32 will be saved in the memory it will be
8:34 saved as a floating Point number with
8:36 some decimal points it will not be saved
8:39 as an integer value it will be saved as
8:42 a floating Point number something like
8:45 12.0 so in typescript and also in
8:48 JavaScript a number is always a floating
8:51 Point number even if we use an integer
8:54 value it will be saved as a floating Point
8:55 Point
8:59 number all right then we also have
9:00 Boolean data
9:04 type so Boolean data type is used to
9:07 store either a value true or false it
9:10 does not have any other value so for
9:12 example if we create a variable let's
9:16 say is eligible to this if we assign
9:19 true the data type of this is eligible
9:21 it is going to be
9:24 Boolean let's create another variable
9:27 let's call it maybe is
9:31 equal and let's let's set it to false so
9:33 again the data type of this is equal is
9:36 going to be Boolean so a Boolean value
9:39 can store only true or false
9:42 value now in typescript just like in
9:44 JavaScript we also have the concept of
9:48 truthy and falsy values so those non-
9:51 Boolean values which when converted to
9:53 Boolean type returns true are called as
9:56 truthy values on the other hand the non-
9:59 Boolean values which returns false when
10:00 converted to Boolean type are called as
10:04 falsy values so for example zero empty
10:07 string null undefined Etc are falsy
10:09 values and all other values are truy
10:13 values so for example if I say
10:17 console.log and if I try to convert Z to
10:21 Boolean so here I'll say Boolean of zero
10:26 okay and if I try to convert 100 to
10:30 Boolean let's save this file and let me
10:33 clear the terminal by typing CLS and
10:35 then let's compile this file by running
10:39 TSC space app.
10:42 TS okay so the file has been compiled
10:44 and you see when we are converting zero
10:47 to Boolean type it is returning false
10:49 and that has been logged and when we are
10:50 converting 100 to Boolean type it is
10:52 returning true and that has been logged
10:56 here in the same way if I use an empty
10:59 string here and here if I use a nonempty
11:02 string so for example a string with a
11:05 space so this is a non-empty string
11:08 right if I save the changes again and if
11:10 you compile the
11:14 code let's refresh the page so you see
11:17 for empty string again it is logging
11:19 false but for a non-m string it is
11:24 logging true let's also try with
11:28 null and here let me specify some string
11:31 value may be hello so this is also a
11:34 non-empty string but null is a falsy
11:36 value let's see that let's save the
11:41 changes let's again compile the app. TS
11:43 file and let's refresh the page and
11:45 again you will see for null false has
11:48 been logged and for hello true has been
11:52 logged so a value which returns true
11:54 when converted to Boolean type is called
11:57 as truthy value and a non- Boolean value
12:00 which when converted to to Boolean type
12:03 returns false that is called as falsy
12:06 value and as I have mentioned for now
12:11 you remember that zero UT string null and
12:12 and
12:15 undefined these are full falsy values
12:17 and in the future we also going to talk
12:19 about other data types in typescript so
12:22 if any other type is also a falsy type
12:24 that also I will mention at that time
12:26 but for now you remember that these four
12:28 values are falsy values and apart from
12:29 these four Val values all other values
12:31 are truthy
12:34 values all right then we also get a
12:37 Boolean value when we compare two values
12:39 when we use comparison operator for
12:41 example let's create a variable let's
12:44 call it is greater and to this we are
12:47 going to assign the result of a
12:50 comparison operation for example 10
12:54 greater than 15 so the result of this
12:56 comparison operation it is going to
12:59 return as a Boolean value right so so if
13:05 greater and here we have this error
13:07 cannot find name is greater that's
13:11 because it should be is greater okay let
13:14 me comment these two lines here let's
13:17 save the
13:22 changes clear the terminal and let's
13:25 compile this app. TS file so the file
13:27 has been compiled and as you can see
13:29 when we have logged in is greater it has
13:31 logged false because 10 is not greater
13:35 than 15 but if I say 10 smaller than 15
13:38 let's save the file again let's compile this
13:39 this
13:41 file and now you will notice that it is
13:43 logging true so the result of a
13:45 comparison operation also returns a
13:48 Boolean value that we can assign to a
13:50 Boolean type and if we hover over this
13:52 is greater variable you will see that
13:54 its type is
13:57 Boolean all right so in this lecture we
13:59 talked about string type number type and
14:02 Boolean type in the next lecture we will
14:04 understand about these types the
14:06 assignment of these types and also what
14:08 is Type
14:10 inference this is all from this lecture