开发者

Simple question: How to do variable concatenation in JavaScript?

开发者 https://www.devze.com 2023-02-01 18:47 出处:网络
In php I can have something like this: $animal = \'horse\'; $animal += \', tig开发者_StackOverflow社区ers\';

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';
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号