哪个在JavaScript String中更有效

时间:2015-09-15 19:57:52

标签: javascript

这两者中更有效的手段可以提供更快的输出 第一个

outString =  "My First String";
outString += "My Second String";
outString += "My Third String";
outString += "My Fourth String";
outString += "My Fifth String";
myFinalString = outString;

或第二个

outString =  "My First String"
          + "My Second String"
          + "My Third String"
          + "My Fourth String"
          + "My Fifth String";
myFinalString = outString;

在其中一个屏幕中我制作的字符串超过100行,那么你会建议哪个?

1 个答案:

答案 0 :(得分:3)

在Chrome中,性能几乎完全相同:

JSPerf

Firefox也显示了类似的结果,所以我不担心你使用哪种语法。

JSPerf结果:https://jsperf.com/javascript-string-test