This section is all about JavaScript strings.
We will dive in more to talk about how to create a string and some of the commonly used methods when
it comes to string.
And also we will learn how to compare string that is string comparison.
And above all, there are going to be a lot of coding challenges at the end of each concept.
So let's get started.
The first question is what is a string?
Where in JavaScript strings are lines of text that are used to store and represent data?
Strings can be anything from a single character to an entire novel or story, so any sequence of characters
can be stored as a string, and string must always be placed within either a single or double quotation
mark.
Well, so strings are everywhere in programming, so we have been using a lot of them.
So a string is also a type of.
Did I type in JavaScript?
So in this video, let's go ahead and learn how to create a string back to visualize clear code.
I have already created a folder and I have named mine folder as strings.
And inside I have two files index HTML and script dot js.
So for the index there are few lines of HTML over here and I just link up my JavaScript file.
There's nothing new until this point, so let's get started with JavaScript.
So let's have a nice command and then write something like Ways of Creating.
Strain.
Well, we have two ways of doing that.
The first method is what you call using the string literature, and now one we have done before.
So let's say that I want to create a string with a keyword const and my variable name, say my name
and then it's equal to then the name I want to use as my name I will say John.
So we see that I can now write or create a string using this quotation mark on them.
So this shows that it's a string, it's a first method.
So if I console.log it, you're going to see John.
Okay, the next method is what you call using the using the constructor.
Function.
So the first one is using.
Strength literature.
So let's talk about how to create a function using the constructor function.
So the same process, my variable name called const and I'll call this one as first name.
And now here we go.
Then I'll bring in new and then string.
Uppercase S for string.
And inside here I can add any string that I can pass in any string that I want to create.
So if you dive in more about JavaScript, we see that this is what you call a class.
We are creating an instance of a string, but A1 is advanced topics.
For now, let's see how to create a string.
So our parsing here, let's say doe for the first name.
So if I console.log this to join my name and first name, let's see the differences.
Well, so let me console.log my name.
My name and then the first name together.
So let me open the console and now you see that I have the two.
First one is John for this one and then the let me have this way.
This one is for this one and then first name is for this.
But we see that there are some differences.
So which one do you think we should use or which one do you think is a preferred way to use?
Well, let me show you here before coming back to this, let's see the differences between these two.
Well, if you try to console.log for the meantime, let's pass in the same value for my name to this
one also as John.
So let's try to compare these two strings because the values are all string.
But if you compare my name to my name and the first name, let's see if you're going to get what is
called true or false.
So let's assign the result to available call result.
And now it's equal to is my name triple equal to first name because for this one it is checking for
the type and a value.
So if I console.log the result down here let's see.
You see that I get false.
But if I remove one equal sign here, then I save it.
I get to remember what we talked about, about the double equality and then the triple equals sign for
the double equal sign.
It only check for the value.
It doesn't take the data type into consideration, but for triple equal to it, check for type and then
the value.
That's what we have foreseeing.
So here the value is the same by the type is different.
So for this method.
We always create an instance of a string out of an object.
That's why you saw an object syntax.
So if you try to console look, first name again, first name again, you can see that.
Let's save it and see that we have a string.
And then inside I have the value called John.
So this this syntax create a string out of an object.
So it tries to compare objects and a string.
I'm going to be forced because objects are always parsed by reference, but string like this one is
not.
So the idea where to go and a shortest way to go is use the string literal.