We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

function Redirect 1



Declares a function with the specified parameters.

You can also define functions using the Function constructor and a function expression.

Version Information

Implemented in JavaScript 1.0
ECMAScript Edition ECMA-262


function [name]([param,[, param,[..., param]]]) {


The function name.
The name of an argument to be passed to the function. A function can have up to 255 arguments.
The statements which comprise the body of the function.


To return a value, the function must have a return statement that specifies the value to return.

A function created with the function statement is a Function object and has all the properties, methods, and behavior of Function objects. See Function for detailed information on functions.

A function can also be declared inside an expression. In this case the function is usually anonymous. See function operator for more information about the function (function expression).

Functions can be conditionally declared. That is, a function definition can be nested within an if statement. Technically, such declarations are not actually function declarations; they are function expressions.


Example: Using function

The following code declares a function that returns the total dollar amount of sales, when given the number of units sold of products a, b, and c.

function calc_sales(units_a, units_b, units_c) {
   return units_a*79 + units_b * 129 + units_c * 699;

See also

Functions, Function, function operator


Document Tags and Contributors

Last updated by: Sheppy,