Join two or more words in javascript

Something Like that:
concat()

The concat() Method
concat() joins two or more strings

For example I want to written HELLO HOME2IT.

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var text1 = "Hello";
var text2 = "Home2it";
res = text1.concat(" ", text2);
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”jLPvGG” default_tab=”result” user=”pradeepanvi”]See the Pen Join two or more words in javascript by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Now you can see.
Hello Home2it

Second option is that

For that you need to create first html code.

HTML

<p id="demo"></p>

After that add this JS code.

JS

var res = "Hello".concat(" ", "Home2it");
document.getElementById("demo").innerHTML = res;

[codepen_embed height=”265″ theme_id=”0″ slug_hash=”MvwqVG” default_tab=”result” user=”pradeepanvi”]See the Pen Join two or more words in javascript 02 by Pradeep Kumar (@pradeepanvi) on CodePen.[/codepen_embed]

Leave a Reply

Your email address will not be published. Required fields are marked *