Simple question: How to do variable concatenation in JavaScript?
In php I can have something like this:
$animal = 'horse';
$animal += ', tig开发者_StackOverflow社区ers';
then the value of animals would be "horse, tigers". How do I do this type of variable concatenation in JavaScript?
Surprise:
'horse' + ', tigers'; // 'horse, tigers'
Now read a good tutorial before asking a thousand more questions:
https://developer.mozilla.org/en/JavaScript/Guide
var szTest = "";
szTest += "One";
szTest += ", Two";
In Javascript you can use the +
to concatenate strings like so,
'horse' + ', tigers';
In PHP the string concatenation operator is .
. So, your example should be:
$animal = 'horse';
$animal .= ', tigers';
var $animal = 'horse';
$animal += ', tigers';
精彩评论