Javascript examples for Operator:Arithmetic Operator
The + operator concatenates (adds) strings.
<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
<!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>