How to use String concat() to add two strings together
Description
concat()
concatenates one or more strings
to another and returns the concatenated string.
Example
var stringValue = "hello ";
var result = stringValue.concat("world");
console.log(result); //"hello world"
console.log(stringValue); //"hello"
/*from w ww .j ava 2 s . c o m*/
The code above generates the following result.
Example 2
The concat()
method accepts any number of arguments:
var stringValue = "hello ";
var result = stringValue.concat("world", "!");
//from w w w .j a va 2 s. c o m
console.log(result); //"hello world!"
console.log(stringValue); //"hello"
The original string is not changed.
The code above generates the following result.