We've worked a bit with JavaScript strings already a string simply stores a series of characters.
For example John Smith a string can be any text inside quotes you can use both single and double quotes.
Let's take a look at an example
in this script.
We have two variables student name 1 and student name two each variable contains the full name of an
individual the first variable contains John Smith and the second contains Roy Martin as you can see
the first name is separated from the last name by a single space the first variable is nested inside.
Double quotes.
The second is nested in single quotes.
Both methods will work.
We have output in each string on an individual line and we've separated each variable using the brake
tag you might recall the brake tag from the H2 M.L.S. of this course.
Let's take a look at what this script looks like in our web browser
here we can see each variable output it on its own line in our web browser.
Now let's take a look at another example to illustrate the use of quotes inside of a string.
We now have three variables.
Line one line two in line three
in line 1.
We use an apostrophe in the first word.
This is acceptable in JavaScript.
Variable line 2 in line 3.
Show the correct method of using quotes inside a string.
You can use quotes as long as they don't match the quotes surrounding the string
so for variable line 2.
We've used double quotes surrounding the string and for that reason single quotes around the name is
Xavier online 3.
We view single quotes surrounding the string and for that reason we've had to use double quotes around
the name exhibitor
we'll save our file and previewed in our web browser and we can see that everything works correctly.
We can see the apostrophe in the first line we can see our single quotes in our double quotes output
it from variable 2 and 3.