Arrays are a very useful data type,
a very useful kind of value for
storing related data
that can be expressed as a list of data.
Basically, just as we had lists in HTML
you could say for outputting related list data.
Sometimes we also have other kinds of related data
which is not just a list
but which
is related,
but needs more context,
so which is not just a list of equal values;
these are all hobbies after all
but instead multiple connected values
that describe different things.
Sounds very abstract.
Let's consider a passport or an ID.
This here,
for example, is the German
ID,
but you have something like this for
every country in the world, I would assume.
And the interesting thing here is that
this of course describes related data in the end,
but we have labels that tell us
which piece of data
describes which trait of this person.
So for example,
we have a label for the name and then we have to value
the actual name of this person.
Last name and the first name,
we have to date of birth and so on.
And we always have these labels
and then the values for these labels.
And overall,
of course,
we can clearly say that this is related data,
all these different pieces of data,
describe one person,
but it's not a list of data because
it's not the same kind of data.
We have names,
dates,
countries,
cities,
different kinds of data on there.
So it's not the same as a list of hobbies
and to describe such kind of data
as well in JavaScript,
we have another important data type,
another important value we can create.
And that would be objects.
Let's say
our
user who visits this website has
a job,
but a job is not just a string where we say
developer,
for example,
but instead,
the job could be a combination of different values,
where we have the name of the company,
the place where he or she works and so on.
And for that, we could create such an object.
We do that with curly braces after this equal sign here.
So opening and closing curly brace,
and between those curly braces,
we now put the different
properties of this object,
the different labels and their values,
that make up, this overall object.
And we call these label value combinations properties
in the context of such a object in JavaScript.
And these labels are up to us.
And we could say that a job is described by a title
and then maybe the place
where this job is being done.
And therefore we could add two labels here,
a title label,
and then separated by a comma,
our
place
label.
And again, these labels are up to you.
You can use any labels you want.
Now the labels on their own are not that useful though.
If we have a look at our passport again,
we did not just have the labels there,
but also values for those labels
and values are now assigned,
not with an equal sign,
but by a colon after our labels.
And then after that colon,
before you have that comma,
and then the next label
you have to value for that label
and values for labels instead of an object.
Can again be all those values you already learned about
strings,
numbers,
arrays,
even other objects.
So-called nested objects,
but that's something we'll explore later.
So here,
our title could be a string
and that could be developer for example,
and then place also needs a value.
So we add a colon and then again,
a value that makes sense here.
So that could again be a string
and it's maybe New York,
maybe a job also has
a Salary.
And that could be a number let's say
50,000
U.S dollars per year
or anything like that.
That could be a job,
a rich object where multiple pieces of data
are grouped together.
Now we could also use
three individual variables.
We could create a variable
job
title
that store's developer
and create another variable
job
place
that store's New York,
and create yet another variable
job
salary
that store's the 50,000.
We could use these three variables instead
of this job object.
We could work with a those of variables in our
subsequent code as well,
but
if we use three individual variables,
instead of one object,
then we as a developer,
always have to kind of keep in mind
that these three variables are logically related.
And that might be easy to do,
especially in a simple script like this,
but it's even easier if you grouped them together
explicitly by creating such an object
just as we created an array for
multiple connected list items,
instead of working with multiple variables.
And that's why here I will not create
three individual variables,
but instead of one object that
has these different properties,
by the way,
you can of course think about these properties as variables
that are
a scoped, that belong to one object.
You don't have to let keyword here though.
You just directly have to label name and then the value.
And you assign that with a colon
instead of an equal sign.
But other than that,
it's basically like variables
that are
closed
into that object.
So to say.