How to define and use a class with static member and static method in TypeScript

2 Answers

0 votes
class Circle {
    static pi: number = 3.14;
    
    static Area(radius:number) {
        return this.pi * radius * radius;
    }
}

console.log(Circle.pi); 

console.log(Circle.Area(7)); 




  
      
/*
      
run:
      
3.14 
153.86 
     
*/

 



answered Oct 25, 2021 by avibootz
0 votes
class Test {
    static index: number = 1;

    static print() {
        console.log(Test.index++);
    }
}

Test.print(); 
Test.print(); 
Test.print(); 


/*
run:
  
1 
2 
3 
           
*/

 



answered Oct 17, 2024 by avibootz

Related questions

1 answer 182 views
1 answer 183 views
1 answer 201 views
1 answer 199 views
1 answer 187 views
1 answer 198 views
1 answer 198 views
...