I need some condition to catch and throw error when a non-function data type is passed as the second argument.
Including undefined being passed?
function test(fn) {
console.log(fn)
// should throw an error if a non-function data type is
//passed as the second argument (includes undefined being passed)
if (fn && typeof fn !== 'function') throw Error();
return fn;
}
function demo() {}
test(); //undefined OK!
test(undefined); // SHOULD THROW ERROR ALSO
// throws error since argument is defined and not a function
test('sdfasfs');