SQL PHP HTML ASP JavaScript articles and free scripts to download
JavaScript String

concat : JavaScript string addition

We can add two or more strings by using concat string function in JavaScript. These function will add strings but we have other different ways to add strings.

We will discuss different ways, before that we will start with syntax of concat function.

variable.concat("string1","string2","string3","string4");

We will use it in a different ways here. First will try to add three strings like this.

var my_var1=" Hello Welcome"
var my_var2=" to plus2net.com "
var my_var3= " JavaScript Section "
var my_var=my_var1.concat(my_var2, my_var3)
document.write(my_var);

The output of above code will be

Hello Welcome to plus2net.com JavaScript Section

We can add three strings directly like this.

var new_var="";
new_var= new_var.concat("First one", " Second One", " Third one ");
document.write(new_var)

By using + operator

We can add strings by using + operation also like this

var my_var1=" Hello Welcome"
var my_var2=" to plus2net.com "
var my_var3= " JavaScript Section "
var my_var=my_var1 + my_var2 + my_var3
document.write(my_var);

Same result we can achieve by using single variable this way

var my_var=""
my_var +=" Hello Welcome"
my_var +=" to plus2net.com "
my_var += " JavaScript Section "
document.write(my_var);


Google+

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked




Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer