The + operator concatenates (adds) strings. - Javascript Operator

Javascript examples for Operator:Arithmetic Operator

Description

The + operator concatenates (adds) strings.

Demo Code

ResultView the demo in separate window

<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w w w.j  a  v  a 2s.com*/
    var text1 = "Good ";
    var text2 = "Morning";
    var text3 = text1 + text2;
    document.getElementById("demo").innerHTML = text3;
}
</script>

</body>
</html>

Or use compound operator

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from ww w . ja  v  a  2  s  .c o  m*/
    var text1 = "Good ";
    var text2 = "Morning";
    text1 += text2
    document.getElementById("demo").innerHTML = text1;
}
</script>

</body>
</html>

Related Tutorials