kb/data/developer.mozilla.org/en-US/docs/Glossary/Function-0.md

12 KiB

title chunk source category tags date_saved instance
Function - Glossary | MDN 1/3 https://developer.mozilla.org/en-US/docs/Glossary/Function reference web, html, css, javascript, documentation 2026-05-05T05:32:08.608917+00:00 kb-cron

MDN HTML HTML: Markup language

HTML reference

HTML guides

Markup languages

CSS CSS: Styling language

CSS reference

CSS guides

Layout cookbook

JavaScriptJS JavaScript: Scripting language

JS reference

JS guides

Web APIs Web APIs: Programming interfaces

Web API reference

Web API guides

All All web technology

Technologies

Topics

Learn Learn web development

Frontend developer course

Learn HTML

Learn CSS

Learn JavaScript

Tools Discover our tools

About Get to know MDN better

Blog

  1. Glossary
  2. Function

Function

A function is a code snippet that can be called by other code or by itself, or a variable that refers to the function. When a function is called, arguments are passed to the function as input, and the function can optionally return a value. A function in JavaScript is also an object. A function name is an identifier included as part of a function declaration or function expression. The function name's scope depends on whether the function name is a declaration or expression.

In this article

Different types of functions

An anonymous function is a function without a function name. Only function expressions can be anonymous, function declarations must have a name: The following terms are not used in the ECMAScript language specification, they're jargon used to refer to different types of functions. A named function is a function with a function name: An inner function is a function inside another function (square in this case). An outer function is a function containing a function (addSquares in this case): A recursive function is a function that calls itself. See recursion. An Immediately Invoked Function Expression (IIFE) is a function that is called directly after the function is loaded into the browser's compiler. The way to identify an IIFE is by locating the extra left and right parenthesis at the end of the function's definition. Function expressions, named or anonymous, can be called immediately. Declared functions can't be called immediately this way, because IIFEs must be function expressions. If you'd like to know more about IIFEs, check out the following page on Wikipedia: Immediately Invoked Function Expression

See also