DEV Community

Swarnali Roy
Swarnali Roy

Posted on • Updated on

Concatenating two Strings with +=

We can easily append variables to a string using the plus equals (+=) operator.

let adjective = "really fun!!";
let str = "Learning basic JavaScript is ";
console.log(str += adjective);
Enter fullscreen mode Exit fullscreen mode

The console will show the output:

Learning basic JavaScript is really fun!!
Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
jcubic profile image
Jakub T. Jankiewicz • Edited

Actually it's not appending, because strings in JavaScript are immutable. You're creating new string and assign it the to the same variable.

Collapse
 
swarnaliroy94 profile image
Swarnali Roy

If you search the google writing "append string in JavaScript" it will show you the concat method of joining two strings together. And append also means the same, concatenation.
Here I have created two variables that holds two different strings and inside the console.log() I've concatenate those two. So that's why I said appending variables.

Collapse
 
devgopal0110 profile image
DEV-GOPAL0110

such a grateful things to learn as beginner in javaScript !!!thank you mam for simplified code !!