This lecture introduces fundamental data types in TypeScript: string, number, and boolean. It explains how to declare and use these types, highlighting their characteristics and common use cases.
Mind Map
Click to expand
Click to explore the full interactive mind map • Zoom, pan, and navigate
in this lecture we going to talk about
some of the code data types in
typescript basically in this lecture we
will talk about string data type number
data type and Boolean data type so all
the values which we assign to a variable
it has a certain type for example a
value assigned to a variable can be a
string value a number value a Boolean
value an object an array Etc so all
these are data types in typescript and
the main data types are string number
and Boolean because these are the three
data types which is used extensively in
any programming language apart from
these three data types we also have
other types of data types which we will
talk about in our coming lectures but in
this lecture let's learn about string
data type number data type and Boolean
data type in
typescript so I'll comment this code
from our previous
lecture and let me copy this heading
here so now we are going to talk about
data types in
typescript and this is lecture
four all
right so first we are going to talk
about string data
type now a string is basically a
sequence of character and in types
script we can create a string by
wrapping some text within double codes
so string is nothing but a text value so
for example let's create a
variable and I'll create this variable
using const keyword and let's call this variable
variable
ST1 now to this we want to assign a text
value a text value is basically a string
type so in order to create a string in
typescript just like in JavaScript we
can create it using single codes like
this so here we can say this is a string
created using single codes
okay so we can create a string using
single codes in the same way we can also
create a string using double codes so
here we can say this is a string created
using double
codes okay and there is practically no
difference when we create a string using
single quotes or double
quotes then we can also create a string
using back text so let's create a
variable let's call it st3
variable so this is also
possible now when we use backticks we
have several benefits so for example if
I try to create a string using single
quotes or double quotes in multiple
lines like this here we will get an
error okay so we cannot create strings
in multiple lines using single Cotes or
double quotes but with backtick we are
not going to get that
error okay it is still being treated as
a string value so using back Tex we can
write our string in multiple
lines and this is the benefit of using
backtick then another benefit is if we
want we can also use template literal
syntax when we are using btic so for
example inside this string if I want to
use a variable somewhere I can simply
use template literal syntax like this
and in here I can specify a variable
name for example we have this sdr1
variable I can use it like this and we
will not get any error and in place of
this the value of St str1 will be
rendered so all these texts will be same
but in place of this template syntax the
value of SDR one variable will be
rendered so this also we can do when we
are using back Texs in order to create a
string but but that is not possible in
strings which we create using single
code or double code okay so here we
cannot do like
that and let's actually check that by
compiling this code so what I will do is
I'll open vs code built-in
terminal and here I want to use command prompt
prompt
okay let me clear the terminal here and
now we want to build we want to compile
this app. TS file so again to compile
app. TS file we can say TSC space app.
TS let's press
enter and here we do not have any error
let's check the Javascript
file all right we do not have any error
because we have not saved the file so it
has compiled the older code and that's
why in the app.js you will see the older
code so let's save this
file and let's compile this .ts
again and now let's see the JavaScript
code so here you can see that that
typescript code has been compiled to
this so here this template lit syntax it
will be rendered as a string it is not
going to replace this s str2 variable
with its value let's actually see that
let's refresh the page here and before
that let's close this app.js let's go
ahead and let's log
S3 let's save the changes let's compile
this app dots file
again it has been compiled and you can
see when we are logging S1 it says this
is a string created then we can see this
dollar s str2 instead of rendering the
value of this s Str 2 it is simply
rendering dollar Str str2 and when we
are using St str3 it says this is a
string created using back Tex and then
it is also logging the value of s str1
and it says this is a string created
using and in s str1 again this part is
not getting replaced with the value of
this Str str2 so that's what you will see
see
here okay so as you can see when we use
back text there we can use template it
syntax and we'll be able to use it properly
properly
but here we cannot use template L syntax
where we are using single Cotes or
double Cotes there it is going to give
us an unexpected result as you can see
here so this is how we create a string
in typescript again let me command this
code and now let's talk about number
type the number type represents both
integer and floating Point number in
typescript so just like in Javas script
we don't have a separate data type for
integer types or floating Point types we
have only one data type called number
which can store both integer values
floating Point numbers or any other type
of numeric value in typescript so in
order to create a number type what we do
is we create a variable let's call it
num and to that we can assign any
numeric value for example 12 like this
so now the data type of this num
variable you can see it is number in the
same way if I create another variable
let's say pi and to this I assign 3.14
so here I'm assigning a floating Point
number to this Pi variable and if I
check the data type of this Pi again you
will notice that its value is 3.14 but
we are not seeing the data type here
that's because it is a constant type but
if I use let keyword here and now if I
over over this Pi you can see that the
data type of this Pi is number but when
we use const at that time also the data
type is going to be Pi but since it is a
constant it is always going to have the
same value 3.14 we are not seeing the
data type now one very important point
you need to remember about the number
type in typescript or JavaScript is that
typescript numbers are always floating
Point numbers which simply means that
they always have decimal even if we
sometimes don't see it so for example
when we assigning this integer value 12
to this number value variable when it
will be saved in the memory it will be
saved as a floating Point number with
some decimal points it will not be saved
as an integer value it will be saved as
a floating Point number something like
12.0 so in typescript and also in
JavaScript a number is always a floating
Point number even if we use an integer
value it will be saved as a floating Point
Point
number all right then we also have
Boolean data
type so Boolean data type is used to
store either a value true or false it
does not have any other value so for
example if we create a variable let's
say is eligible to this if we assign
true the data type of this is eligible
it is going to be
Boolean let's create another variable
let's call it maybe is
equal and let's let's set it to false so
again the data type of this is equal is
going to be Boolean so a Boolean value
can store only true or false
value now in typescript just like in
JavaScript we also have the concept of
truthy and falsy values so those non-
Boolean values which when converted to
Boolean type returns true are called as
truthy values on the other hand the non-
Boolean values which returns false when
converted to Boolean type are called as
falsy values so for example zero empty
string null undefined Etc are falsy
values and all other values are truy
values so for example if I say
console.log and if I try to convert Z to
Boolean so here I'll say Boolean of zero
okay and if I try to convert 100 to
Boolean let's save this file and let me
clear the terminal by typing CLS and
then let's compile this file by running
TSC space app.
TS okay so the file has been compiled
and you see when we are converting zero
to Boolean type it is returning false
and that has been logged and when we are
converting 100 to Boolean type it is
returning true and that has been logged
here in the same way if I use an empty
string here and here if I use a nonempty
string so for example a string with a
space so this is a non-empty string
right if I save the changes again and if
you compile the
code let's refresh the page so you see
for empty string again it is logging
false but for a non-m string it is
logging true let's also try with
null and here let me specify some string
value may be hello so this is also a
non-empty string but null is a falsy
value let's see that let's save the
changes let's again compile the app. TS
file and let's refresh the page and
again you will see for null false has
been logged and for hello true has been
logged so a value which returns true
when converted to Boolean type is called
as truthy value and a non- Boolean value
which when converted to to Boolean type
returns false that is called as falsy
value and as I have mentioned for now
you remember that zero UT string null and
and
undefined these are full falsy values
and in the future we also going to talk
about other data types in typescript so
if any other type is also a falsy type
that also I will mention at that time
but for now you remember that these four
values are falsy values and apart from
these four Val values all other values
are truthy
values all right then we also get a
Boolean value when we compare two values
when we use comparison operator for
example let's create a variable let's
call it is greater and to this we are
going to assign the result of a
comparison operation for example 10
greater than 15 so the result of this
comparison operation it is going to
return as a Boolean value right so so if
greater and here we have this error
cannot find name is greater that's
because it should be is greater okay let
me comment these two lines here let's
save the
changes clear the terminal and let's
compile this app. TS file so the file
has been compiled and as you can see
when we have logged in is greater it has
logged false because 10 is not greater
than 15 but if I say 10 smaller than 15
let's save the file again let's compile this
this
file and now you will notice that it is
logging true so the result of a
comparison operation also returns a
Boolean value that we can assign to a
Boolean type and if we hover over this
is greater variable you will see that
its type is
Boolean all right so in this lecture we
talked about string type number type and
Boolean type in the next lecture we will
understand about these types the
assignment of these types and also what
is Type
inference this is all from this lecture
Click on any text or timestamp to jump to that moment in the video
Share:
Most transcripts ready in under 5 seconds
One-Click Copy125+ LanguagesSearch ContentJump to Timestamps
Paste YouTube URL
Enter any YouTube video link to get the full transcript
Transcript Extraction Form
Most transcripts ready in under 5 seconds
Get Our Chrome Extension
Get transcripts instantly without leaving YouTube. Install our Chrome extension for one-click access to any video's transcript directly on the watch page.