Java Script


JavaScript Tutorial


Admission Enquiry Form

Concatenation Operator in JavaScript

The "+" operator can also be used as concatenation operator in JavaScript. It is used to concatenate two strings, string variables, integer and strings together.

Example of concatenating strings

<html>
<head>
<title>Example of concatenating strings</title>
</head>
<body>
<script>

document.write("Welcome "+"Compuhelp");
</script>
</body>
</html>


Output:

Welcome Compuhelp


Example of concatenating string variables

<html>
<head>
<title>Example of concatenating string variables</title>
</head>
<body>
<script>
var str1="Welcome";
var str2="Compuhelp";
document.write(str1+str2);
</script>
</body>
</html>



Output:

Welcome Compuhelp


Example of concatenating string with integer

<html>
<head>
<title>Example of concatenating string with integers</title>
</head>
<body>
<script>
var num1=10;
var num2=20;
var res=num1+num2;
document.write("The sum is "+res);
</script>
</body>
</html>



Output:

The sum is 30