Reputation: 1185
This is probably very stupid question, but why do we say "string concatenation" whereas it is actually used for at least integer literals as well?
// JavaScript
var var1 = "foo"; // string literal
var var2 = "bar"; // string literal
var var3 = 20; // integer literal
var var4 = var3; // integer literal
var concatenated = var1.concat(var2).concat(var3).concat(var4)
alert(concatenated);
Or, probably, integer literals are treated in programming as a subset of string literals, and therefore the current terminology is correct?
Upvotes: 0
Views: 31
Reputation: 41503
As a mathematical operation, "concatenation" is an operation over two sequences. A string is one kind of sequence, so "string concatenation" is a reasonable term to use, in that it is strings you are concatenating. (Similarly, one might also use the term "integer addition", even though if you have two integers it's pretty obvious what kind of addition you're going to do.)
Concatenation is not defined for things that aren't sequences, like the number 20. The code you've shown first converts the number 20
into the string "20"
, then uses that as an operand for concatenation.
Upvotes: 1