CKTIS / JavaScript
function — declarations and expressions
The function keyword defines a function with parameters and a body. Learn the difference between a declaration and a function expression, and how return supplies a result.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
function name(parameter) { return parameter; }
const otherName = function (parameter) { return parameter; };function is a reserved keyword: it cannot be a variable name. It introduces a function declaration or a function expression. Parameters appear in (), and the body in {}; defining a function does not execute its body.
A declaration, such as function add(a, b) { return a + b; }, names the function. An expression, such as const double = function (value) { return add(value, value); };, creates a function value when the expression is evaluated; the name after function is optional.
Calling double(4) runs the body with the supplied argument. In an ordinary function, return ends execution and supplies a result to the caller. Reaching the end of the body without return produces undefined.
Examples
"use strict";
function add(a, b) {
return a + b;
}
const double = function (value) {
return add(value, value);
};
console.log(double(4));Result
8
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.