How to use private and public members in class in TypeScript

1 Answer

0 votes
class Employee {
    eName: string|undefined; // public
    private eID: number;
}

let emp = new Employee();

emp.eName = "R2D2";
// emp.eID = 3937; // Property 'eID' is private and only accessible within class 'Employee'.(2341)

console.log(emp.eName);


  
      
/*
      
run:
      
"R2D2" 
     
*/

 



answered Oct 25, 2021 by avibootz

Related questions

1 answer 134 views
1 answer 145 views
1 answer 184 views
...