Question :
I was noticing that in JavaScript the String
object has a method called concat
. It serves to do the same thing as the +
operator does.
"Meu nome é " + nome
Already with concat
would look like this:
"Meu nome é ".concat(nome)
In particular, I believe that using the String.concat
method would be more organized. But I would like to know first if it is guaranteed that this will work in all current browsers.
Is this a recent function? Can I use it without fear?
Note : To be sure, this question is being asked in the year 2016.
Answer :
This method has no security issues, it has long been supported by browsers.
It may be personal, but I find it odd to use it in concatenations. Obviously the operator can do odd coercion, but that’s another problem. My code organization avoids this kind of thing.
The method performance is poor compared to the operator . Worse until the join()
. At least that’s what I gave in my test. This may vary by implementation.
The documentation recommends using the operator.