JavaScript: literal string with the concat() function

The tutor shares an observation about the concat() function.

The concat() function is used to join one or more strings to the end of another:

var strng0 = “This string, “;
var strng1 = “then this one”
var strng2 = “:)”
var strng3 = strng0.concat(strng1,strng2);
document.getElementById(“output”).innerHTML = strng3;

will display

This string, then this one:)

In my experience, a literal string can also be used at the front:

var strng_a = “then this one”
var strng_b = “:)”
var strng_c = “This string, “.concat(strng_a,strng_b);
document.getElementById(“output”).innerHTML = strng_c;

will also display

This string, then this one:)

Source:

www.w3schools.com

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Tagged with: ,

Leave a Reply