title: TypeScript Default Value for property
body: <p>I have defined an Interface in TypeScript like below:</p>
  
  <pre><code>export interface User {
      id?: number;
      name?: string;
      logoUrl?: File;   
      emailUserName?: string;
      emailPassword?: string;
  }
  </code></pre>
  
  <p>With User, I bind it to Angular html input. If I enter anything in the input, the User Object will contains the value, But, If I do not enter, the property like name will be undefine. How could I get empty value for name if I do not enter string for name.
  Update</p>
  
  <pre><code>&lt;div *ngIf="hero"&gt;
  &lt;h2&gt;{{hero.name}} details!&lt;/h2&gt;
  &lt;div&gt;
  &lt;label&gt;id: &lt;/label&gt;{{hero.id}}&lt;/div&gt;
  &lt;div&gt;
  &lt;label&gt;name: &lt;/label&gt;
  &lt;input [(ngModel)]="hero.name" placeholder="name" /&gt;
  &lt;input [(ngModel)]="hero.location" placeholder="location" /&gt;
  &lt;/div&gt;
  &lt;button (click)="goBack()"&gt;Back&lt;/button&gt;
  &lt;/div&gt; 
  //model
      export class Hero {
      private _location:string="test";
      constructor(){
      console.log(this._location);
      this.location=this._location;
      }
      public id: number;
      public name: string;
      public location:string;
      } 
  
  goBack(): void {
  console.log(this.hero);
  // this.hero=new Hero();
  // console.log(this.hero);
  //this.location.back();
  }
  } 
  </code></pre>
  
  <p>goBack will output hero without location property if I do not enter any value for it in input.</p>