title: Getter/Setter In Typescript
body: <p>I was following a tutorial on Typescript Classes and the person teaching created a class and some setter/getter methods.But when i read <a href="https://www.typescriptlang.org/docs/handbook/classes.html" rel="noreferrer">Typescript Documentation</a> the approach was somewhat different. Can someone help me understand the difference between both approaches.</p>
  
  <p>Approach 1:</p>
  
  <pre><code>class Student {
  private _name: string;
  
  constructor(name:string) {
      this._name=name;
  }
  
  getName = (): string =&gt; {
      return this._name;
  }
  
  setName = (name: string) =&gt; {
      this._name = name;
  }
  }
  </code></pre>
  
  <p>Approach 2:</p>
  
  <pre><code>class Student {
  private _name: string;
  
  constructor(name:string) {
      this._name=name;
  }
  
  public get name(): string {
      return this._name;
  }
  
  
  public set name(value: string) {
      this._name = value;
  }
  }
  </code></pre>
  
  <p>Have a look. In Approach 1 we write getter/setter as normal functions But in Approach 2 the keyword get/set is used. Can someone help me understand the difference between both approaches.</p>