title: in javascript why use " var that = this "
body: <p>hi i am new with javascript</p>
  
  <p>What is the benefit of using this line</p>
  
  <p><code>var that = this</code></p>
  
  <p>An example</p>
  
  <pre><code>function Person( firstname, lastname, age ) {
  
      this.firstname = firstname;
  
      this.lastname = lastname;
  
      this.age = age;
  
      getfullname = function() {
  
          return firstname + “ “ + lastname;
      };
  
      var that = this;
  
  
      this.sayHi = function() {
  
          document.write( “Hi my name is “ + getfullname() + “ and I am “ + that.age + “years old.”);
  
      };
  }
  </code></pre>
  
  <p>thanks</p>