xxxxxxxxxx
let string1 = "Hello"
let string2 = "World"
let finalString = string1 + ", " + string2 + "!" // Hello, World!
xxxxxxxxxx
var str1 = "Hello ";
var str2 = "world!";
var res = str1.concat(str2);
// does not change the existing strings, but
// returns a new string containing the text
// of the joined strings.
xxxxxxxxxx
var str1 = "Hello ";
var str2 = "world!";
var res = str1.concat(str2);
console.log(res);
xxxxxxxxxx
//This method adds two or more strings and returns a new single string.
let str1 = new String( "This is string one" );
let str2 = new String( "This is string two" );
let str3 = str1.concat(str2.toString());
console.log("str1 + str2 : "+str3)
output:
str1 + str2 : This is string oneThis is string two
xxxxxxxxxx
const str1 = 'Hello';
const str2 = 'World';
console.log(str1.concat(' ', str2));
// expected output: "Hello World"
console.log(str2.concat(', ', str1));
// expected output: "World, Hello"
xxxxxxxxxx
const num1 = [2, 4, 5, 3, 8, 9, 11, 33, 44];
const num2 = [22, 33, 44, 55, 66, 77, 88];
const concatNumbers = num1.concat(num2)
console.log(concatNumbers)
//Expected output:
/*[
2, 4, 5, 3, 8, 9,
11, 33, 44, 22, 33, 44,
55, 66, 77, 88
]
*/
xxxxxxxxxx
let first_string = 'I am a programmer, ';
let second_string = 'I am indisposable.';
let what_i_said = first_string + second_string;
console.log(what_i_said);
/* OR
*/
let tell_my_boss = first_string.concat(second_string);
console.log(tell_my_boss);
xxxxxxxxxx
const str1 = 'Hello';
const str2 = 'World';
console.log(str1 + str2);
>> HelloWorld
console.log(str1 + ' ' + str2);
>> Hello World
xxxxxxxxxx
var fruit="";
if(true){fruit +="Apple";;}
if(true){fruit +=" + Orange";}
if(true){fruit +=" + Banana";}
if(false){fruit +=" + Mango";}
console.log(fruit);
// Output: Apple + Orange + Banana
xxxxxxxxxx
let a = "foo";
let b = ["f", "o", "o"];
let c = a.concat("bar"); // "foobar"
let d = b.concat(["b", "a", "r"]); // ["f","o","o","b","a","r"]
xxxxxxxxxx
const array1 = [1, 2, 3, 4, 5];
const array2 = [6, 7, 8, 9, 10];
const array3 = [11, 12, 13, 14, 15];
const mergeArray = array1.concat(array2, array3);
console.log(mergeArray);