JavaScript typeof Operator Program to Check If a Variable is of Function Type at Run Time Full Project For Beginners

 

 

script.js

 

 

// program to check if a variable is of function type

function testVariable(variable) {
      
    if(typeof variable === 'function') {
        console.log('The variable is of function type');
    }
    else {
        console.log('The variable is not of function type');
    }
}

const count = true;
const x = function() {
    console.log('hello')
};

testVariable(count);
testVariable(x);

Leave a Reply