Back to Freecodecamp

Concatenating Strings with Plus Operator

curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244b7.md

latest1.6 KB
Original Source

--description--

In JavaScript, when the + operator is used with a String value, it is called the <dfn>concatenation</dfn> operator. You can build a new string out of other strings by <dfn>concatenating</dfn> them together.

Example

js
'My name is Alan,' + ' I concatenate.'

Note: Watch out for spaces. Concatenation does not add spaces between concatenated strings, so you'll need to add them yourself.

Example:

js
const ourStr = "I come first. " + "I come second.";

The string I come first. I come second. would be displayed in the console.

--instructions--

Build myStr from the strings This is the start. and This is the end. using the + operator. Be sure to include a space between the two strings.

--hints--

myStr should have a single space character between the two strings.

js
assert(/start\. This/.test(myStr));

myStr should have a value of the string This is the start. This is the end.

js
assert(myStr === 'This is the start. This is the end.');

You should use the + operator to build myStr.

js
assert(__helpers.removeJSComments(code).match(/(["']).*\1\s*\+\s*(["']).*\2/g));

myStr should be created using the const keyword.

js
assert(/const\s+myStr/.test(__helpers.removeJSComments(code)));

You should assign the result to the myStr variable.

js
assert(/myStr\s*=/.test(__helpers.removeJSComments(code)));

--seed--

--seed-contents--

js
const myStr = ""; // Change this line

--solutions--

js
const myStr = "This is the start. " + "This is the end.";