coderef

FunctionsBaseline · Widely available

Functions are series of statements that can be called and return a value. The function keyword (as in function () { }) and arrow (=>) expression create functions. The JavaScript functions protocol includes default and rest parameters and binding to this.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Jul 29, 2015. Widely available since Jan 29, 2018.

Browser support

DesktopChrome
1+Supportedsince Dec 11, 2008
Current: 155
Edge
12+Supportedsince Jul 29, 2015
Current: 154
Firefox
1+Supportedsince Nov 9, 2004
Current: 157
Safari
1+Supportedsince Jun 23, 2003
Current: 27
MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155
Firefox Android
4+Supportedsince Mar 29, 2011
Current: 157
Safari iOS
1+Supportedsince Jun 29, 2007
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: Function.

Feature detection

JS · check before using
// Syntax can't be tested with an if-statement — an unsupported
// browser fails to parse the whole script. Either transpile for older
// targets (e.g. Babel/TypeScript/esbuild), or probe in isolation:
let supported = true;
try {
  new Function("/* code that uses the syntax */");
} catch {
  supported = false;
}

This is a language syntax feature.

Sub-features

Support for each part of the feature (38). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Function112111841
Function.@@hasInstance50155010505010
Function.Function112111841
Function.apply112111841
Function.apply.generic_arrays_as_arguments1712461846
Function.bind71245.11846
Function.call112111841
Function.length112111841
Function.length.configurable_true43123710433710
Function.name1514161846
Function.name.configurable_true43143810433810
Function.name.inferred_names51795310515310
Function.toString112111841
Function.toString.toString_revision66795417665417
javascript.functions112111841
javascript.functions.arguments112111841
javascript.functions.arguments.@@iterator521246952469
javascript.functions.arguments.length112111841
javascript.functions.arrow_functions45122210452210
javascript.functions.arrow_functions.trailing_comma58125210585210
Show 18 more
Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
javascript.functions.block_level_functions49124610494610
javascript.functions.default_parameters49141510491510
javascript.functions.default_parameters.destructured_parameter_with_default_value_assignment49144110494110
javascript.functions.default_parameters.parameters_without_defaults_after_default_parameters49142610492610
javascript.functions.get1121.531841
javascript.functions.get.computed_property_names4612349.146349.3
javascript.functions.method_definitions391234939349
javascript.functions.method_definitions.async_methods55155210.1555210.3
javascript.functions.method_definitions.generator_methods_not_constructable4213439.142439.3
javascript.functions.rest_parameters47121510471510
javascript.functions.rest_parameters.destructuring49795210495210
javascript.functions.set1121.531841
javascript.functions.set.computed_property_names4612349.146349.3
trailing_commas.trailing_commas_in_functions58145210585210
function112111841
function.trailing_comma58145210585210
function112111841
function.trailing_comma_in_parameters58145210585210