Home » JavaScript

String concat() Method with Example in JavaScript

JavaScript String concat() Method: Here, we are going to learn about the concat() method in JavaScript with example.
Submitted by IncludeHelp, on February 07, 2019

String concat() Method

concat() is a string method in JavaScript, it is used to concatenate (join) two or more strings and returns a new joined string.

Syntax:

    String.concat(string1, string2, ...);

It accepts string(s) and returns new string (which is joined string with the main string).

Examples:

    Input:
    str1 = "IncludeHelp"
    str2 = ".com"
    Function call: str1.contact(str2);
    Output:
    "IncludeHelp.com"

    Input:
    str1 = "Hello"
    str2 = " " //space
    str3 = "World!"
    Function call: str1.contact(str2, str2);
    Output:
    "Hello World!"

Code:

<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>		
	var str1 = "IncludeHelp";
	var str2 = ".com";
	document.write(str1.concat(str2) + "<br>");

	str1 = "Hello";
	str2 = " ";
	var str3 = "World!";
	document.write(str1.concat(str2, str3) + "<br>");	
</script>
</body>
</html>

Output

IncludeHelp.com
Hello World!





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.