How to count the times a function has been called in TypeScript

1 Answer

0 votes
let functionCallCounter = 0;
 
function add(a : number, b : number) {
  functionCallCounter += 1;
 
  return a + b;
}
 
add(1, 2);
 
add(3, 4);
 
add(5, 6);

add(7, 8);
 
console.log(functionCallCounter);
 
   
   
   
   
/*
run:
   
4
   
*/

 



answered May 6, 2022 by avibootz
...