JavaScript Scratches

String Concatenation

Previously, we showed how to break up long lines with the string conatenation operator ( + ).

But what is concatenation, and how else can we use it?

Simply put, it means joining several individual strings into one.

let nameF="Stephen";
let nameL="O'Toole";
Sprint ('<br/>Your name is ' + nameF + ' ' + nameL + '<br/>');

Or assign a contenated string and do something with it:

let nameFull = nameL+ ',' + nameF;
Sprint('<br/>Or is it ' + nameFull + '?<br/>');

When dealing with numbers and strings, the operation converts (if possible) the number to a string, and treats it as such.

let aString="10";
let aNumber=42;
let aNumbStr=aString + aNumber;
Sprint('<br/>A number plus a string = ' + aNumbStr + '<br/>');
String Split