- [Maximilian] So that's how we can create objects.
Now, the bigger your objects get
the harder it can get to fully read
and understand them if you are looking at code like this.
And that's why typically we split objects
and their properties across multiple lines.
After the opening curly brace,
we often add a line break to have the first key value pair.
The label is our key
and then this is the value.
And after the comma,
if we have another property,
we add another line break.
And again,
and then another one in front of the closing curly brace.
This is a bit easier to read.
And hear you now see that some
white space was added automatically by my IDE.
It's not required technically, we could remove it
and the code works either way.
But of course,
it is a bit easier to read if we do have that white space,
and if you wanna re add it,
you can simply hit the tab button
and it will automatically indented a bit
or that format document button
or shortcut,
which also will automatically format this.
And that's now simply a bit easier to read.
You could also add line breaks like this for arrays,
if you wanted to,
if that helps you with readability.
And there,
it also makes sense if this would be a longer array,
but for this array,
I think having it in one line is okay as well.
But you could add those line breaks as well.
Now, when it comes to adding a line breaks
and splitting code across multiple lines,
there also are a couple of other rules
which are worth keeping in mind.
And for example,
inside of a string,
so between those quotes,
you are not allowed to add a line break.
You'll see, I'm getting an error here in my IDE,
if I try to do that.
If you would have a longer text
and you wanna split it across multiple lines,
there are two main ways of doing that.
You can either add a plus here,
which actually will add another string to the first one,
it will combine two strings together.
so you can use plus not just with numbers,
but also with strings.
And then you could have your other string in a new line
and that would work because JavaScript would understand
that it should look for another value
that belongs to this operation in the next line.
So that would work.
You could even write it like this
and it would still work.
That is all valid Java script,
though typically you would not write it like this because
that's not super obvious
that this belongs together.
But you can split longer strings like this.
Alternatively,
you can also use back ticks instead of single quotes.
It looks similar,
but it's a different character on your keyboard.
And if you use such back ticks,
then you can actually add a line break inside of the string.
So that would be an alternative for longer text.
Here I will go back to single quotes since
those are also easier to reach for me on the keyboard
and are more commonly used.
But these back ticks can actually help you,
if you need such a line break inside of the string.
Now throughout the course,
you will also see some other line breaks here
and there and you will see how I structure my code.
I will also typically explain
why something is structured in a certain way,
but in general, as a developer,
especially in JavaScript code,
but also in HTML code,
where we also work with indentation
and new lines,
our goal is always code readability.
We always want to write our code,
no matter which kind of code it is,
such that it's easy to read,
that is easy to grasp,
and we don't need to check if
there are multiple statements in one of the same line,
but instead we go for short lines,
concise code and clearly structured code.
And that's there for also
what we'll go for in this course
and what we'll teach you in this course.