Javascript string size limit: 256 MB for me - is it the same for all browsers?
<p>Curious about what was the maximum string length I could get in Javascript, I tested it myself, today, on my Firefox 43.0.1, running in Windows 7. I was able to construct a string with length <code>2^28 - 1</code>, but when I tried to create a string with one more char, <a href="http://getfirebug.com/" rel="noreferrer">Firebug</a> showed me the <em>"allocation size overflow"</em> error, meaning the string must be less than 256 MB.</p>

<p><strong>Is this the same thing for all browsers, all computers, all operational systems, or it depends?</strong></p>

<p>I created the following snippet to find out the limit:</p>

<pre><code>(function() {
    strings = ["z"];
    try {
        while(true) {
            strings.push(strings[strings.length - 1] + strings[strings.length - 1]);
        }
    } catch(err) {
        var k = strings.length - 2;
        while(k &gt;= 0) {
            try {
                strings.push(strings[strings.length - 1] + strings[k]);
                k--;
            } catch(err) {}
        }
        console.log("The maximum string length is " + strings[strings.length - 1].length);
    }
})();
</code></pre>

<p>If you are running a different browser/OS, I would like to see your results. My result was <em>The maximum string length is 268435455</em>.</p>

<p><strong>P.S.:</strong> I searched around for an answer, but the most recent topic I found was from 2011, so I am looking for a more up-to-date information.</p>