Is it safe to use JavaScript's String.concat method in current browsers?

3

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.

    
asked by anonymous 10.03.2016 / 16:19

2 answers

5

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.

    
10.03.2016 / 16:34
2

It is safe, the function is old and you can use it without fear (it already comes from standard 1.2 of js, this is netscape 1997!) however it is not recommended because performance is pitiful compared to + , += and% with%. See the test: link (de link ).

    
10.03.2016 / 16:33