Back to Lessons

JavaScript Functions

April 5, 2026

Functions

Reusable blocks of code with parameters and return values.

Function Examples

// Function declaration
function greet(name) {
    return "Hello, " + name;
}

// Function expression
const add = function(a, b) {
    return a + b;
};

// Arrow function (ES6)
const multiply = (x, y) => x * y;

console.log(greet("John")); // "Hello, John"

Key Points

  • Function declaration hoisted, expressions not.
  • Arrow functions: concise, lexical this.
  • Default parameters: function(x = 1).
  • Rest parameters: ...args.