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 136 views
2 answers 149 views
1 answer 120 views
1 answer 132 views
1 answer 207 views
1 answer 135 views
...