Project Euler #4 - finding the largest palindrome from the product of two n-digit numbers
Javascript numbers are stored in IEE754 format that can precisely represent numbers up to 2^53 - 1 (9007199254740991), so it's impossible to use the built-in Javascript arithmetic to get actual digits for a lot of two 8-digit number products (for example, 94,906,266 * 94,906,266 exceeds the abovementioned maximum).

There are several BigNumber libraries for JavaScript, but I'll only give an answer for the case of 7 digits and less. A brute-force enumeration with a couple of optimization is quite fast for n&lt;7 compared to the original OP code that took 1370 ms for 3 digits and 3+ minutes for 4 digits.

function largestPalindromeOfTwoFactors(len1, len2) {
    // calculate number range for n digits:  10^(n-1)..10^n-1 (e.g. 10-99)

    // 'a' (outer loop) will be the largest multiplicand
    var maxA = Math.pow(10, Math.max(len1, len2)) - 1 |0;
    var minA = (maxA + 1) / 10 |0;

    // 'b' (inner loop) will be the smallest multiplicand
    var maxB = Math.pow(10, Math.min(len1, len2)) - 1 |0;
    var minB = (maxB + 1) / 10 |0;

    var maxMul = 0, maxMulA, maxMulB;

    for (var a = maxA; a &gt;= minA; a--) {
        // in case len1==len2 only process 'b' smaller than current 'a'
        // as the larger numbers were already checked when used for 'a'
        for (var b = Math.min(a, maxB); b &gt;= minB; b--) {
            var mul = a * b;
            if (mul &lt;= maxMul) {
                // no need to continue, we'll never exceed maxMul with a smaller 'b'
                break;
            }
            var mulStr = mul.toString();
            for (var i = mulStr.length-1, j=0; i&gt;=j &amp;&amp; mulStr[i] == mulStr[j]; i--, j++) {}
            if (i &lt;= j) {
                maxMul = mul, maxMulA = a, maxMulB = b;
                // 'a' smaller than current 'b' won't produce a bigger product
                minA = Math.max(minA, b);
            }
        }
    }
    // retain the order of input parameters' magnitudes: 2,3 -&gt; 99, 951
    return [maxMul, len1 &lt; len2 ? maxMulB : maxMulA, len1 &lt; len2 ? maxMulA : maxMulB];
}


Test run:

for (var i=1; i&lt;=7; i++) {
    var start = Date.now();
    console.log('%o in %d ms', largestPalindromeOfTwoFactors(i, i), Date.now() - start);
}



  [9, 9, 1] in 0 ms
  [9009, 99, 91] in 0 ms
  [906609, 993, 913] in 2 ms
  [99000099, 9999, 9901] in 1 ms
  [9966006699, 99979, 99681] in 551 ms
  [999000000999, 999999, 999001] in 171 ms
  [99956644665999, 9998017, 9997647] in 162363 ms &lt;&lt;&lt;&lt;&lt;&lt; ughhhh


Notes:


There are much better algorithms.
090 isn't a number, 90 is, so the former and the likes are not palindromes.