How to check if a function is defined in TypeScript

1 Answer

0 votes
if (typeof add === 'function') {
  	console.log('add function is defined');
} else {
  	console.log('add function is not defined');
}

function toHexArray(arr : any) {
 
}

if (typeof toHexArray === 'function') {
  	console.log('toHexArray function is defined');
} else {
  	console.log('toHexArray function is not defined');
}
  
 
 
 
   
/*
run:
  
"add function is not defined" 
"toHexArray function is defined" 
   
*/

 



answered May 27, 2022 by avibootz

Related questions

1 answer 147 views
1 answer 132 views
1 answer 155 views
2 answers 155 views
1 answer 210 views
...