An interesting solution to get all prime numbers smaller than n | Javascript program to prints prime numbers smaller than n ; Compute factorials and apply Wilson 's  theorem. ; Driver code
function primesInRange ( n ) { let fact = 1 ; for ( let k = 2 ; k < n ; k ++ ) { fact = fact * ( k - 1 ) ; if ( ( fact + 1 ) % k == 0 ) document . write ( ( k + " " ) ) ; } } let n = 15 ; primesInRange ( n ) ;