Optional parameters function ( hàm tham số tùy chọn) là gì?

{{FormatNumbertoThousand(model.total_like)}} lượt thích
2.828 lượt xem

Chúng ta có thể chỉ định các thuộc tính tùy chọn trên các inteface và thuộc tính có thể có hoặc thiếu trong 1 object.

//USER INTERFACE

interface User

{

   name: string;

   age: number;

   address?: string //Optional

}

//FUNCTION USING USER INTERFACE

let userInfo = function(user: User) 
               { 
                  let info = "Hello, " + user.name + " Your Age is - " + user.age + " and 
                              Address is -" + user.address; 
                  return info; 
                } 

//USER INFO JSON OBJECT 

let info = { name: "Anil", age: 30 }; 

//RESULT console.log(userInfo(info));
Câu hỏi tiếp theo: Rest parameters function là gì?
{{login.error}}