Power function in JavaScript
For a power function with an integer exponent you can loop through the bits in the exponent instead of making a linear loop:

function pow(base, power) {
    if (power &lt; 0) return 1 / pow(base, -power);
    var b = base, result = 1;
    while (power &gt; 0) {
        if ((power &amp; 1) != 0) {
            result *= b;
        }
        power &gt;&gt;= 1;
        b *= b;
    }
    return result;
}


This will only loop as many times as there are bits used in the exponent, for a value like 1000 that means 10 iterations instead of 1000.

Testing this with pow(2, 1000) in Firefox shows that it is about 70 times faster (but the built in method is still even 8 times faster).