Basic JavaScript - Concatenating Strings with the Plus Equals Operator

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

let myStr;
myStr += "This is the first sentence. This is the second sentence.";

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Concatenating Strings with the Plus Equals Operator

Link to the challenge:

Hi there and welcome to our community!

You have declared an empty variable and then tried to concatenate both strings together.
Unfortunately this doesn’t work as, when you declare a variable without a value initially, it is undefined. If you then try to concatenate, you’ll simply end up with:
undefinedThis is the first sentence. This is the second sentence.

You should change the declaration to assign the first string and then use concatenation to add the second string to the first.

EXAMPLE:

let thisString = "hello";
thisString += " world";
console.log(thisString) // "hello world"

thanks it worked
i realises where the challenge was and rectified it

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.