Such as
var myName = 'Bob';
myName += ' is a good name';
For long operations of this, it there a better way to do it? Maybe with a StringBuffer type of structure?
Thanks! :)
The ‘better’ way would be:
var nameparts= ['Bob'];
nameparts.push(' is a good name');
...
nameparts.join('');
However, most modern JavaScript implementations do now detect naïve concatenation and can in many cases optimise it away, because so many people have (alas) written code this way. So in practice the ‘good’ method won't today be as much faster as it once was.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With