cf.
http://en.wikipedia.org/wiki/Perfect_number
since perfect numbers are relatively sparse (only 7 within the first 150 billion numbers) it were more efficient to check against that.
alas, that’s not your task.
you could use Euclid’s proof ( 2^(p−1) * (2^p − 1) ) for even numbers and try that factorisation, which is certainly faster than a full factorisation of the original number* (the reason digital certificates are secure—you cannot efficiently factorise a very large number) which reduces the proof to that the second factor is a Mersenne prime (of which there are 47 known).
* - unless you’re using small numbers
and now for the JavaScript part: JS numbers are IEEE 754 double precision floats, which means that you have 16 digits in a range of about 10^308 numbers. and having 16 decimal places is what limits you with regard to exactness. certainly it is still more efficient to look up the perfect numbers.
yet, if you want to do a full factorisation, you’ll need the factors up to sqrt(number_to_test). which leaves you with a loop up to 100 billion calculation cycles (only if you restrict the number to exactness level). with a rough estimate of 10,000 cycles per second, this can take about 2 - 3 hours (in which case any browser will time out the script).