How to check if a function is defined in Node.js

1 Answer

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

function toOctArray(arr) {
 
}

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

 



answered May 27, 2022 by avibootz

Related questions

1 answer 227 views
2 answers 256 views
1 answer 203 views
1 answer 211 views
1 answer 287 views
1 answer 212 views
...