Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed String Manipulation with JavaScript !
You have completed String Manipulation with JavaScript !
Preview
In JavaScript, strings are treated similarly to objects and are provided with built-in methods and properties. These methods allow us to modify strings as well as search for values within strings.
Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
One of the benefits of JavaScript is
that it allows us to build websites and
0:09
applications that people
can interact with.
0:13
This interaction is often in the form
of user input, like entering words or
0:16
other characters into a web form.
0:21
As a JavaScript developer,
you will often work with this user input.
0:24
For example, you might have to
remove whitespace or search for
0:28
values within user input.
0:32
When it comes to storing user input,
0:34
JavaScript commonly relies
on the string data type.
0:36
The string type Describes
variables made up of letters and
0:40
other sequences of characters
wrapped in quotation marks.
0:44
Strings can include not only letters,
but also numbers and symbols.
0:49
strings in JavaScript
are said to be immutable.
0:54
This means they can't be altered or
updated.
0:58
JavaScript treats the string similar
to an object, providing properties and
1:01
built in methods that allow us to
access and manipulate string values.
1:07
These methods can't change the value
of a string once it's defined,
1:13
but instead,
return a completely new string object.
1:17
Let's open up the console and
give this a try.
1:20
We'll take the familiar
to uppercase method and
1:25
apply on a variable named state,
that stores the string California.
1:28
We'll first define the variable
1:34
We'll need to make sure that
all the letters are lowercase.
1:46
Now we'll apply the two uppercase
method to the state variable.
1:50
We see CALIFORNIA in all capital letters.
2:00
But when we check the value of state
again, it's still in all lowercase.
2:05
String methods take
the value of a string and
2:12
output values based on
the selected method.
2:14
With string methods, we use the format
string dot methodName, parentheses.
2:18
Many of these string methods take
an index value as a parameter.
2:25
Like with arrays, bracket notation allows
us to access string characters using
2:29
index values that start at zero.
2:34
For instance,
2:37
we can access the third character of
a string using bracket notation by
2:38
passing in the number two to access the
item at index two using bracket notation.
2:43
Access the character at
zero of our state variable.
2:50
The console will log out C.
2:55
Nice.
3:07
Coming up,
we'll explore two groups of methods.
3:08
Those for searching a string and
methods for modifying a string value.
3:12
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up