Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 751589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:41:02+00:00 2026-05-14T14:41:02+00:00

Strings in JavaScript are immutable. Across the web and here on Stack Overflow as

  • 0

Strings in JavaScript are immutable. Across the web and here on Stack Overflow as well, I came across the Array approach to concatenate strings:

var a = []; 

a.push(arg1,arg,2....);
console.log(a.join(''));

I know that this approach is better than the simple

console.log(arg1 + arg2 +.....);

for reasons of skipping creating intermediate objects but how does it fair better against :

arg1.concat(arg2,arg3.....);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:41:03+00:00Added an answer on May 14, 2026 at 2:41 pm

    For what it may count, I tried the following test:

    var stringA = 'someStringA';
    var stringB = 'someStringB';
    var stringC = 'someStringC';
    
    var arr = [];
    arr.push(stringA);
    arr.push(stringB);
    arr.push(stringC);
    
    // Testing the concat method
    i = 0;
    console.time('10k concat');
    while (i < 10000) {
        stringA.concat(stringB, stringC);
        i++;
    }
    console.timeEnd('10k concat');
    
    // Testing the join method
    i = 0;
    console.time('10k join');
    while (i < 10000) {
        arr.join(''); 
        i++;
    }
    console.timeEnd('10k join');
    

    Results in Firefox 3.6.3 on Mac OS X 10.6.2:

    10k concat: 20ms
    10k join: 15ms
    
    10k concat: 20ms
    10k join: 16ms
    
    10k concat: 19ms
    10k join: 15ms
    

    Results in Chrome 5.0 on Mac OS X 10.6.2:

    10k concat: 22ms
    10k join: 14ms
    
    10k concat: 20ms
    10k join: 16ms
    
    10k concat: 20ms
    10k join: 16ms
    

    UPDATE:

    If we were to count the array creation in the join('') test, we would see a different story. Testing:

    var stringA = 'someStringA';
    var stringB = 'someStringB';
    var stringC = 'someStringC';
    
    // Testing the concat method
    i = 0;
    console.time('10k concat');
    while (i < 10000) {
        stringA.concat(stringB, stringC);
        i++;
    }
    console.timeEnd('10k concat');
    
    // Testing the join method
    i = 0;
    console.time('10k join');
    while (i < 10000) {
        var arr = [];
        arr.push(stringA);
        arr.push(stringB);
        arr.push(stringC);
        arr.join(''); 
        i++;
    }
    console.timeEnd('10k join');
    

    Results in Firefox 3.6.3 on Mac OS X 10.6.2:

    10k concat: 20ms
    10k join: 40ms
    
    10k concat: 21ms
    10k join: 40ms
    
    10k concat: 20ms
    10k join: 42ms
    

    Results in Chrome 5.0 on Mac OS X 10.6.2:

    10k concat: 20ms
    10k join: 55ms
    
    10k concat: 22ms
    10k join: 60ms
    
    10k concat: 19ms
    10k join: 60ms
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a one-dimensional array of strings in JavaScript that I'd like to turn
So far, I've only been passing javascript strings to my web methods, which get
If a string is immutable, does that mean that.... (let's assume JavaScript) var str
I have a group of strings in Javascript and I need to write a
Is there a way to convert variable names to strings in javascript? To be
I'm trying to get a case-insensitive search with two strings in JavaScript working. Normally
In javascript, we can do: [a string, 10, {x : 1}, function() {}].push(another value);
Possible Duplicate: Multiline strings in Javascript In Ruby you can do something like this:
How would one get resx resource strings into javascript code stored in a .js
I'm having problems passing utf-8 strings to javascript (ajax). Currently i'm using rawurlencode on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.