DEV Community

Discussion on: Let's optimize JavaScript - password generator (2.15x faster)

inhuofficial profile image

Just wondering, is it faster to do

  password = password.concat(combinedCaracters[this._random(0, length)]);
Enter fullscreen mode Exit fullscreen mode

vs just

  password += combinedCaracters[this._random(0, length)];
Enter fullscreen mode Exit fullscreen mode

I would imagine as concat is not performant it would be faster.

Only glanced at it though so I might have missed a good reason for concat.

Thread Thread
nombrekeff profile image
Keff Author

I though that too, but I did some benchmarks, and found out concat to perform a bit faster than +=. It was not the most extensive benchmark, and it might vary from browser to browser and such... but would be interesting to know though