How to check if an object contains a function in Node.js

1 Answer

0 votes
const obj = {
  div: (a, b) => {
    return a / b;
  },
};

console.log(typeof obj.div);

console.log(typeof obj.div === 'function' ? "contains a function" : "not contains a function");




/*
run:
 
function
contains a function
  
*/

 



answered Jun 2, 2022 by avibootz
...