title: hasNext() for ES6 Generator
body: <p>How would I implement hasNext() method for a generator. I have tried many options like adding the generator as a return statement and yielding from the closure. Getting the first value printing it and then using the while etc, but none of them actually worked. </p>
  
  <p>I know I can use for of or while like <a href="https://stackoverflow.com/questions/34333852/how-to-loop-the-javascript-iterator-that-comes-from-generator">How to loop the JavaScript iterator that comes from generator?</a>  but still wondering if I can add hasNext(). </p>
  
  <pre><code>function *range(start,end){
  
      while(start &lt; end){
          yield start; 
          start++
      }
  }
  
  let iterator = range(1,10); 
  
  // so I can do something like this. 
  while(iterator.hasNext()){
     console.log(iterator.next().value); 
  }
  </code></pre>