title: Caching in Javascript without usage of global variable
body: <p>I am trying to optimise the usage of a function to check whether a number is prime or not.</p>
  
  <p>I have written the following function:</p>
  
  <pre><code>function isPrime(num) {
      var start = 2;
  
      // code to check whether num has already been checked for Prime
  
      while(start &lt;= Math.sqrt(num)) {
        if (num % start++ &lt; 1) {
          return false;
        }
      }
      return num &gt; 1;
  }
  </code></pre>
  
  <p>However, before the execution of my <code>while</code> loop I want to check if a number already has been passed through my isPrime function, so that I can return whether it is prime or not without having to execute the <code>while</code> loop.</p>
  
  <p>Note, I want to do this without the usage of a global variable or without extending <code>Object.prototype</code>.</p>