Learning to Code: Day 39 — Basic JavaScript Part 4

Hello everyone, welcome back. I’ve been a bit out the loop as I have had several other things to deal with before these blogs, and now I’m sitting in the middle of a full blown cold, I thought it give this JavaScript another bash. Let’s get back on that old horsey. Thanks as always to FreeCodeCamp for the lessons…

Escape Sequences in Strings

So where were we? Ah yes, looking at how to escape quotations inside a string. But it’s not the only character we can escape, so to speak. Here’s a table according to FFC that can better illustrate how to escape different types of characters, all preceded with a backslash:

- FreeCodeCamp

Note: The backlash also has to be preceded by a backslash so as not to error.

Concatenating Strings with a Plus Operator

Yeah me too, I read that as concentrating as well.

What we’re talking about here is how by using the plus “+” operator with several strings, it becomes a concatenating operator. Concatonate meaning to “link together”. Sounds pretty straight forward. If we say:

var myStr = “Here is a string. ” + “Here is another.”;

Then we get:

Here is a string. Here is another.


Remember: Don’t forget to have a space after the end of the first string so they don’t appear joined like so:

This is a string.Here is another.

Concatenating Strings with the Plus Equals Operator

Using the “+=” operator, we can break down potentially longer strings over several lines. The code reads these lines in sequence so the sentence is built as the code is written. Remember these spaces between strings too:

var myStr = “First. ”;

myStr += “Second.”;

This will make:

First. Second.

Constructing Strings with Variables

It’s possible to create string sentence with pre-determined variables, which when using the plus operator, will concatenate (man I hate that word) them into the string. Here’s an example:

var myDog = “Charlie”;

var myStr = “My dog is called ” + myDog + “and he is 5.”;

You guessed it, this will create the string sentence:

My dog is called Charlie and he is 5.

Append Variables to Strings

Now we have a hang of the plus equals operator and variables, we can append a string sentence purely from pre-defined variables. If we first define the variables, we can then concatenate (ugh..) them together:

var myStr = “This is ”;

var myDog = “Charlie”;

myStr += myDog;

This will make:

This is Charlie

Aaaaand let’s leave it there. I’m way too stuffed up on Ibuprofen to see clearly right now, and I think I have a hold of my thoughts here enough to say I need a break! See you guys tomorrow. Peace out.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Hugh Burgess

Hugh Burgess

Step by step, learning to code with FreeCodeCamp