Computer >> Computer tutorials >  >> Programming >> Javascript

How can I check if a JavaScript variable is function type?


Use “typeof” to check whether it’s a function or not. You can try to run the following code to check if a JavaScript variable is function type:

Example

Live Demo

<html>
   <body>
      <script>
         var res = function(){
            //
         };
         if (typeof res === "function") {
            alert("A function")
         }
      </script>
   </body>
</html>