Function Types in javascript

Common function types in JavaScript include: function declarations (hoisted), function expressions (assigned to a variable), arrow functions (short syntax with lexical this), methods on objects, Immediately Invoked Function Expressions (IIFEs), and constructor functions (called with new). Understanding their differences helps you choose the right one and avoid this‑related bugs.

Example

// Declaration (hoisted)
function greet(name) {
  return `Hi ${name}`;
}

// Expression
const square = function (n) {
  return n * n;
};

// Arrow (no own 'this')
const double = n => n * 2;

// Method on object
const counter = {
  value: 0,
  inc() {
    this.value++;
  },
};

// IIFE
(function () {
  console.log("Runs immediately");
})();

Each style has different behavior for hoisting and this; most modern code prefers declarations for named functions and arrows for small callbacks.