Ways of appending 2 or more strings in Javascript.

vishalneeraj-24503
Posted by vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 1235
There are 2 ways to append strings in Javascript.With the help of Concat() method and + sign,we can append 2 or more strings.

For Example:-
<script type="text/javascript" language="javascript">

function concatenate_string()
{
var val1 = "vishal";
var val2 = " neeraj";

//1st method using concat() method
var concat_value1 = val1.concat(val2);
alert(concat_value1);

//2nd method using + sign
val1 = "vishal";
val2 = " kumar";
var val3 = " neeraj";
var concat_value2 = val1 + val2 + val3;
alert(concat_value2);
}

</script>


<body onload="concatenate_string();">
</body>

Output will be
1). vishal neeraj
2). vishal kumar neeraj

Comments or Responses

Login to post response