Function Type in JavaScript

🔍 What is a Function Type?

In JavaScript, functions are first-class objects, which means they can be treated like any other value — assigned to variables, passed around as arguments, or returned from other functions.

Functions are of the "function" type, but internally, they are actually a special kind of object.

📌 Checking Function Type

typeof on Function

function greet() {
  console.log("Hello!");
}

console.log(typeof greet); // "function"

Note

💡 Even though functions are technically objects, typeof returns "function" — a special case in JavaScript.

🧱 Function Internals

A JavaScript function has:

  • 🔁 A callable behavior (can be invoked)
  • 🧬 Properties and methods (like an object)
  • ⚙️ A hidden [[Call]] method that allows it to be called

🧪 Function as Object

Function as Object

function sayHi() {
  console.log("Hi");
}

sayHi.language = "JavaScript";

console.log(sayHi.language); // "JavaScript"

Note

💡 Yes, functions can have properties like regular objects!

👨‍💻 Different Ways to Create Functions

  • Function Declaration: function name()
  • Function Expression: const fn = function()
  • Arrow Function: const fn = () =>
  • Constructor Function: new Function(...args)

All Function Forms

function add(a, b) {
  return a + b;
}

const subtract = function(a, b) {
  return a - b;
};

const multiply = (a, b) => a * b;

const divide = new Function("a", "b", "return a / b;");

🛠 typeof and instanceof

typeof vs instanceof

function test() {}

console.log(typeof test);        // "function"
console.log(test instanceof Function); // true
console.log(test instanceof Object);   // true

Note

🧠 Functions are instances of both Function and Object!

📚 Summary Table

CheckResultDescription
typeof fn"function"Special case for functions
fn instanceof FunctiontrueAll functions are Function instances
fn instanceof ObjecttrueFunctions are objects too

📖 Further Reading

>>“In JavaScript, functions aren't just code — they're objects with power.” 🚀