JS字符串“+” vs concat方法 [英] JS strings "+" vs concat method

查看:489
本文介绍了JS字符串“+” vs concat方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Java有一些经验,我知道字符串连接与+运算符会产生新对象。

I have some experience with Java and I know that strings concatenation with "+" operator produces new object.

我想知道如何以最好的方式在JS中做到这一点,最佳做法是什么?

I'd like to know how to do it in JS in the best way, what is the best practice for it?

推荐答案

MDN对 string.concat()

MDN has the following to say about string.concat():


出于性能原因,强烈建议使用字符串连接运算符
(+,+ =)而不是此方法

It is strongly recommended to use the string concatenation operators (+, +=) instead of this method for perfomance reasons

另见@Bergi链接。

Also see the link by @Bergi.

这篇关于JS字符串“+” vs concat方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆