Is it safe to use Javascript’s String.Concat method in current browsers?

Asked

Viewed 86 times

6

I was observing that in Javascript the object String has a method called concat. Serves to do the same thing as the operator + ago.

"Meu nome é " + nome

Already with concat would look like this:

"Meu nome é ".concat(nome)

Particularly, I believe with the method String.concat would be more organized. But I would like to know first if it is guaranteed that so will work in all current browser.

Is this feature recent? Can I use it fearlessly?

Note: For the record, this question is being asked in the year 2016.

  • 2

    Do you swear you think it’s more organized? Safe in what way? I can’t imagine a security problem specific to this method.

  • I’m sorry, I meant "safe" in the sense of "assured it will work". kkkkk

2 answers

5


This method has no security problems, is long supported by browsers.

I think it’s weird to use it in concatenations. Obviously the operator can do weird coercion, but that’s another problem. My code organization avoids this sort of thing.

To performance of the method is poor compared to the operator. Worse until the join(). At least that’s what you gave me in my test. This may vary according to the implementation.

The very documentation recommends the use of the operator.

  • OK. I changed my mind after I saw the tests. Thanks +1

3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.