function expression - JavaScript | MDN

developer.mozilla.org

Tin mới

HTML: Markup language

See all HTML references

Date & time formats

See all HTML guides

CSS: Styling language

See all CSS references

See all CSS guides

Centering an element

JavaScript: Scripting language

Standard built-in objects

Expressions & operators

Statements & declarations

See all JavaScript references

Control flow & error handing

Loops and iteration

Working with objects

See all JavaScript guides

Web APIs: Programming interfaces

Service worker API

Using the Web animation API

Using the Fetch API

Working with the History API

Using the Web speech API

All web technology

Progressive web apps

Learn web development

Getting started modules

Structuring content with HTML module

CSS styling basics module

Dynamic scripting with JavaScript module

Border-image generator

Border-radius generator

Box-shadow generator

Color format converter

function declaration

The function keyword can be used to define a function inside an expression.

expression statement

Note: An expression statement cannot begin with the keyword function to avoid ambiguity with a function declaration. The function keyword only begins an expression when it appears in a context that cannot accept statemen

Functions reference

The name of a formal parameter for the function. For the parameters' syntax, see the Functions reference.

Named function expression

If you want to refer to the current function inside the function body, you need to create a named function expression. This name is then local only to the function body (scope). This avoids using the deprecated arguments

Named function expression

If you want to refer to the current function inside the function body, you need to create a named function expression. This name is then local only to the function body (scope). This avoids using the deprecated arguments

Using a function as a callback

Using an Immediately Invoked Function Expression (IIFE)

Here, we introduce several use cases with examples.

Using an Immediately Invoked Function Expression (IIFE)

Here, we introduce several use cases with examples.

block-scoped declarations

Here, we introduce several use cases with examples.

Using an Immediately Invoked Function Expression (IIFE)

Here, we introduce several use cases with examples.

Learn how to contribute

This page was last modified on Aug 21, 2026 by MDN contributors.

Expressions and operators

Numbers and strings

Representing dates & times

Regular expressions

Indexed collections