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: 155Edge
12+Supportedsince Jul 29, 2015
Current: 154Firefox
1+Supportedsince Nov 9, 2004
Current: 157Safari
1+Supportedsince Jun 23, 2003
Current: 27MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155Firefox Android
4+Supportedsince Mar 29, 2011
Current: 157Safari iOS
1+Supportedsince Jun 29, 2007
Current: 27How 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-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| Function | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| Function.@@hasInstance | 50 | 15 | 50 | 10 | 50 | 50 | 10 |
| Function.Function | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| Function.apply | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| Function.apply.generic_arrays_as_arguments | 17 | 12 | 4 | 6 | 18 | 4 | 6 |
| Function.bind | 7 | 12 | 4 | 5.1 | 18 | 4 | 6 |
| Function.call | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| Function.length | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| Function.length.configurable_true | 43 | 12 | 37 | 10 | 43 | 37 | 10 |
| Function.name | 15 | 14 | 1 | 6 | 18 | 4 | 6 |
| Function.name.configurable_true | 43 | 14 | 38 | 10 | 43 | 38 | 10 |
| Function.name.inferred_names | 51 | 79 | 53 | 10 | 51 | 53 | 10 |
| Function.toString | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| Function.toString.toString_revision | 66 | 79 | 54 | 17 | 66 | 54 | 17 |
| javascript.functions | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| javascript.functions.arguments | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| javascript.functions.arguments.@@iterator | 52 | 12 | 46 | 9 | 52 | 46 | 9 |
| javascript.functions.arguments.length | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| javascript.functions.arrow_functions | 45 | 12 | 22 | 10 | 45 | 22 | 10 |
| javascript.functions.arrow_functions.trailing_comma | 58 | 12 | 52 | 10 | 58 | 52 | 10 |
Show 18 more
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| javascript.functions.block_level_functions | 49 | 12 | 46 | 10 | 49 | 46 | 10 |
| javascript.functions.default_parameters | 49 | 14 | 15 | 10 | 49 | 15 | 10 |
| javascript.functions.default_parameters.destructured_parameter_with_default_value_assignment | 49 | 14 | 41 | 10 | 49 | 41 | 10 |
| javascript.functions.default_parameters.parameters_without_defaults_after_default_parameters | 49 | 14 | 26 | 10 | 49 | 26 | 10 |
| javascript.functions.get | 1 | 12 | 1.5 | 3 | 18 | 4 | 1 |
| javascript.functions.get.computed_property_names | 46 | 12 | 34 | 9.1 | 46 | 34 | 9.3 |
| javascript.functions.method_definitions | 39 | 12 | 34 | 9 | 39 | 34 | 9 |
| javascript.functions.method_definitions.async_methods | 55 | 15 | 52 | 10.1 | 55 | 52 | 10.3 |
| javascript.functions.method_definitions.generator_methods_not_constructable | 42 | 13 | 43 | 9.1 | 42 | 43 | 9.3 |
| javascript.functions.rest_parameters | 47 | 12 | 15 | 10 | 47 | 15 | 10 |
| javascript.functions.rest_parameters.destructuring | 49 | 79 | 52 | 10 | 49 | 52 | 10 |
| javascript.functions.set | 1 | 12 | 1.5 | 3 | 18 | 4 | 1 |
| javascript.functions.set.computed_property_names | 46 | 12 | 34 | 9.1 | 46 | 34 | 9.3 |
| trailing_commas.trailing_commas_in_functions | 58 | 14 | 52 | 10 | 58 | 52 | 10 |
| function | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| function.trailing_comma | 58 | 14 | 52 | 10 | 58 | 52 | 10 |
| function | 1 | 12 | 1 | 1 | 18 | 4 | 1 |
| function.trailing_comma_in_parameters | 58 | 14 | 52 | 10 | 58 | 52 | 10 |