How to check if a variable is of function type in TypeScript

1 Answer

0 votes
function isfunctiontype(variable: any) {
    return variable instanceof Function
}

const b = true;
console.log(isfunctiontype(b));

const a = function() {
    return 12
};
console.log(isfunctiontype(a));




/*
run:

false
true

*/

 



answered Jan 27, 2022 by avibootz

Related questions

1 answer 133 views
1 answer 124 views
1 answer 134 views
2 answers 251 views
1 answer 116 views
1 answer 207 views
1 answer 133 views
...