Concatenation Operator

Concatenation Operator is used to combine string together. In another words it joins two string. In most programming language + operator is used to concatenate two words. But in some language the concatenation operator is different. For example, in PHP, . (Dot) operator is used for concatenate two words. However their functionality is same.

let firstName = "Santanu";
let lastName = "Bera";
let fullName = firstName + " " + lastName;

Remember this operator only works on String type. If you do it on the other data type, this operator will try to convert the value into string, and then the concatenation happens. If implicit conversion to string fails, it returns error. For example, trying to use concatenatation operator on array data type. Most programming doesn't offer implicit conversion for array to string data type. For those programming language, it will result an error.

Addition Vs Concatenation

As the symbols are same for both operator, there is a simple rule - "If both left and right operand is number type then the addition operation is performed. If one of them is string, then the concatenation is performed."