Hello and welcome.
In this video I will introduce you to some javascript data types in programming in general and also
in JavaScript the data types basically refers to the classification that specifies the type of value
that a variable has or stores.
There are different types of data types in JavaScript.
Here's a basic table with some basic javascript data types.
So I'm going to start with the top one which is this string.
This trend basically is a sequence of text that must be enclosed in quotes.
You can use either single quotes or double quotes but you cannot mix the quotes.
For example here you can declare a variable called my data and set it to this value.
You can see I've got quotes around it.
I've got my web console open so the way to access your WAP web console if you are on a Windows computer
open up just Google home page and type in control shift and Jay on your keyboard o f 12 and that would
give you access to the Web console if you are on a Mac you do command shift and J that would give you
access to the console.
So let's create a simple variable that will store a string data type so in my console.
I'm going to create a new variable by typing in the keyword V A r and I'm going to call this variable
my colors okay.
And I'm going to give it a value gonna give this value or read.
So that's a value you can see I've enclosed the value in quotes which means if a string data type A
computer will recognize that as a string data type.
So if I want to reference this variable all I need to do is call it by its name and age or just return
the value read.
So that's a simple example of how a string data type can be used.
The next data type I want to mention is the number data type basically refers to any numerical value.
And it does not need to have a quote around its value to let me illustrate by creating a simple variable
or store in no data type.
So I declare a simple variable by typing in the keyword var and I'll call this variable door
Don number and I'll give it a value of 7.
So this is known as a no data type.
You can see it doesn't need ports around it.
So if I want to reference that variable I just call it by its name Don number and it will return the
value of seven the next data type.
I want to mention it's called a boolean a boolean basically represents two values that one can be true.
The other can be false and we're using boolean values no quotes required to illustrate a billion of
value.
I'm just going to compare two values.
I'm going to say four is greater than three.
That will return true and a five say three is greater than four.
And that will return false.
So that's basically how boolean value data types work the next day to type.
I want to mention is called an array an array is a data structure that stores multiple values as one
single reference.
Basically what that means a variable can store only one value but with an array you can store multiple
values as one single reference.
You can see here I've got two values here.
Ford and Toyota both I'm referencing it on the one variable called my cars.
So let me show you a quick illustration.
Inside the console someone should declare a variable called my cars
and I'm going to set it to a course to and this is how you declare an array with square brackets and
inside the square brackets is where you place the values.
So let's say the first value I say it's a Ford and second value I say is a Toyota.
When you are using a raise you separate each of the values with a comma.
The only way you don't need a comma is the very last value.
So this basically here is an array and the way you access the values in an array is via the index.
So the way an array is for France is by the index.
So this will be known as zero index.
This will be one if you have several.
You can have as many as possible inside the square brackets but you need to separate the values with
a comma.
And if they are on the string data type you enclose it in quotes.
If they are not then you don't need to enclose it in quotes.
So for example if I wanted to access value.
Number one this is zero index zero which is Ford Hall I need to do is typing my cards
and in lowercase type in my cars and then in square brackets.
I type in value zero which will represent the index I'm trying to target and that should return.
You can see it has returned Ford.
So that's how you.
If I had like 20 inside here I will reference it fiber index based Val number.
So Ford the very first values that zero index to hit I would be index number one and so on so that's
how you access the values in an array.
So the key difference between an array and variable is that an array can store multiple values as one
value.
If you see here I got just got this variable called my colors and is only stored one value here I've
got a variable called my car's only stores multiple values by reference as a single values core my car's
next data type I want to quickly mention it's called the object everything in Javascript is basically
an object.
So all the examples I have shown so far they are basically objects can also represent JavaScript objects
with curly braces as I've done here I've declared a variable called Person set the value to cause to
the first name got John last name though so you can represent an object like this way as well but by
using curly braces.
So if I wanted to access this object here all I need to do is call the variable by its name and it will
return the.
You can see he's returned the first name as John last name as do another data type.
I want to introduce you to court.
No you may come across this in your learning with JavaScript and basically in no data type is something
that does not exist.
You can also use the normal data type to empty the value of a variable and a normal is also an Object
data type so you can see here got a variable here called Door Number and with a value of 7 so I can
empty that value by just typing in the name of the variable which is number and set in the value to
know and that will empty the current data it stores if I call these variable codon door number now it
will come back saying no because I've emptied out the whatever it was storing.
Okay.
So a null data type means basically nothing.
He doesn't store anything doesn't lock in in the final data type.
I want to talk about is called undefined undefined is similar to No.
The only difference is that the different data type on defined is undefined while in no data type is
also an object data type or if you declare a variable you don't give it a value that will become undefined.
For example if I call me and say variable suites
and I don't give it any value.
That would become undefined if I tried to call it by its name.
It would come back undefined.
So that's a key difference key difference between a normal and undefined.
Is that undefined is not an object data type.
While normal is an object data type so that's basically it for this video on javascript data types.
Thanks for watching.
Bye for now.