Now there is one last
characteristic about strings which I want to show to you,
which is related to arrays actually.
Let's say we have a certain username
Max here in this case,
and now we want to find out how long that name is.
As a human we can count it,
but we don't always want to count because it's error prone.
And in our running application, in our running website,
that variable value might actually not be hard coded into
this code as it's currently.
But instead we might be fetching this from some input field
on the page, and that is actually something
we will be doing in this demo I showed you earlier.
Which we are going to build in the next course section,
because in this demo we need to count
the length of the user input,
which of course changes with every keystroke
and which we as a developer therefore don't know
in advance, and in situations like this we need a way of
finding out how long some text is.
So it's not something we need here for this example,
this hard coded string,
which means a value we define as a developer,
which never changes,
which does not depend on some input of the website visitor.
Here it is just hard coded, and therefore,
we could count it manually,
but let's assume we're getting this from
some dynamic input, and we don't know the length in advance.
In such cases, we might want to derive the length
programmatically,
and that is thankfully easy to do in Java script.
We can just use the string that we want to count,
or the variable that holds the string,
which I have in this case
and then use the dot notation to access dot length.
And that's really important, and maybe also confusing.
A string is not an object.
And yet we can use the dot notation on a string
to access various methods.
Since we have this purple kind of blocks here,
on that string, and we also have this length property,
in addition to all these methods.
Now this is simply something that's built into JavaScript.
You could say that all the strings you are creating are
automatically wrapped with an invisible object behind the
scenes, by Java script,
so that you have certain properties that you can access on
your strings.
So they kind of are converted into objects behind the scenes
and we have this behavior
so that we have certain functionalities or utilities
that we can access on these strings.
Like for example, dot length,
to get the length of this string,
the number of characters that make up this string.
And if I saved this, then I get three here as a result,
which of course is the length of this Max string.
And as you can see, if I,
again add a dot here and I get this suggestion popup,
there is way more than just length.
And you see we have a bunch of methods here,
which we can access on our string,
and that length property which we saw.
And definitely feel free to play around with them.
For example, there is the toUpperCase method,
and since it's a method we need to execute it
by adding these parentheses here.
And if I call that, then I get this string
converted to all uppercase characters.
So these are utility functionalities,
which can come in handy from time to time.