Return the Closest Prime Number Challenge

This is a simple one: Given a positive integer up to 1,000,000, return the closest prime number.

If the number itself is prime, then you should return that number; if there are two primes equally close to the provided number, return the lower of the two.

Input is in the form of a single integer, and output should be in the form of an integer as well.

I don't care how you take in the input (function, STDIN, etc.) or display the output (function, STDOUT, etc.), as long as it works.

This is code golf, so standard rules apply&mdash;the program with the least bytes wins!

Test Cases

Input  =&gt;  Output
------    -------
80     =&gt;      79
100    =&gt;     101
5      =&gt;       5
9      =&gt;       7
532    =&gt;     523
1      =&gt;       2
JavaScript (ES6), 53 bytes

n=&gt;(g=(o,d=N=n+o)=&gt;N%--d?g(o,d):d-1?g(o&lt;0?-o:~o):N)``

Try it online!
Commented
n =&gt; (            // n = input
  g = (           // g = recursive function taking:
    o,            //   o = offset
    d =           //   d = current divisor, initialized to N
    N = n + o     //   N = input + offset
  ) =&gt;            //
    N % --d ?     // decrement d; if d is not a divisor of N:
      g(o, d)     //   do recursive calls until it is
    :             // else:
      d - 1 ?     //   if d is not equal to 1 (either N is composite or N = 1):
        g(        //     do a recursive call with the next offset:
          o &lt; 0 ? //       if o is negative:
            -o    //         make it positive (e.g. -1 -&gt; +1)
          :       //       else:
            ~o    //         use -(o + 1) (e.g. +1 -&gt; -2)
        )         //     end of recursive call
      :           //   else (N is prime):
        N         //     stop recursion and return N
)``               // initial call to g with o = [''] (zero-ish)