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

JavascriptWeb DevelopmentFront End Technology

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>
raja
Published on 18-Jan-2018 08:25:41
Advertisements