String operators

In addition to the comparison operators, which can be used on string values, the concatenation operator (+) concatenates two string values together, returning another string that is the union of the two operand strings.

For example,

JSCopy to Clipboard

console.log("my " + "string"); // console logs the string "my string".

The shorthand assignment operator += can also be used to concatenate strings.

For example,

JSCopy to Clipboard

let mystring = "alpha";
mystring += "bet"; // evaluates to "alphabet" and assigns this value to mystring.

Last updated