I've implemented Miller-Rabin Primality Test in Javascript using the BigInt type.
Time complexity for this algorithm should be O(k * log^3(n))
, where n is the tested number and k is the number of rounds performed (higher k means higher probablity of correct result).
For more information about Miller-Rabin Primality Test and mathematics behind it please see e.g. https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test.