title: Global variables use inside the class instance JavaScript
body: <p>I have a class declared and exported in one js file. Inside this file my class instance can use global variable. I import this class to the tests file and there I face a problem that the variable is not defined.</p>
  <p>this is my class</p>
  <pre><code>export class GuessingGame {
      setRange(min, max) {
          this.min = min
          this.max = max
      }
      guess() {
          if(this.min + 1 === number) {
              return this.min + 1
          } else if(this.max - 1 === number) {
              return this.max - 1
          } else {
          return Math.round((this.max - this.min) / 2 + this.min)
          }
      }
      lower() {
          if(this.guess() &gt; number) {
              this.max = this.guess()
          }
      }
      greater() {
          if(this.guess() &lt; number) {
              this.min = this.guess()
          }
      }
  }
  </code></pre>
  <p>And if I declare var number inside the file with this class - the class instance can use it without any errors. But!</p>
  <p>This is the test file, where it should use the global variable const number. But it gives me error  ReferenceError: number is not defined</p>
  <pre><code>import { GuessingGame } from './rolling-scopes-guessing-game.js';
  import chai from 'chai';
  import sinonChai from'sinon-chai';
  
  global.expect = chai.expect;
  chai.use(sinonChai);
  
  describe('GuessingGame', () =&gt; {
  describe('#guess', () =&gt; {
  it('should guess number 409 with max value 4048', () =&gt; {
      const number = 409;
      const game = new GuessingGame();
      game.setRange(0, 4048)
  
      let result = game.guess();
      game.lower();
      result = game.guess();
      game.lower();
      result = game.guess();
      game.lower();
      result = game.guess();
      game.greater();
      result = game.guess();
      game.greater();
      result = game.guess();
      game.lower();
      result = game.guess();
      game.lower();
      result = game.guess();
      game.greater();
      result = game.guess();
      game.greater();
      result = game.guess();
      game.greater();
      result = game.guess();
      game.lower();
      result = game.guess();
  
      expect(result).to.equal(number);
      });
  });
  });
  </code></pre>