• Scope: by default members in a class are public
  • Enum: an enum is a way of giving more friendly names to sets of numeric values
    • String enum: use custom Type. See more here.
  • Do we put return type when defining function?
    Yes. getSum(a: number, b: number): number {}

  • Type assertion: (<string>someValue).length;

  • We have static, readonly

    • const is for varibale. No one can modifiy it after assigned.
    • readonly is for property (class property to property in interface). Properties must be initialized at their declaration or in the constructor. It only ensures that it won't be modified by me. Others can still modify it. See here
    • static must be class member.
  • Function overload, this is possible in TypeScript but it's not supported by JavaScript.

  • Default paramter: getSum(data: number[], skipNegative: boolean = false)

  • Destructuring (FP concept)

    // pick only the data we need using destructing
    // Function signature: getAccountInfo(): {balance: number; cardStatus: string; cardNumber: string; cardHolder: string}
    const {balance, cardStatus} = this.getAccountInfo();

results matching ""

    No results matching ""