| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/function | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..
function .
Function .
var myFunction = function [name]([param1[, param2[, ..., paramN]]]) {
statements
};
name. , . .
paramN, .
statements, .
. , . IIFE (Immediately Invoked Function Expression), , . .
JavaScript (hoisting), . , .
console.log(notHoisted); // undefined
// ,
notHoisted(); // TypeError: notHoisted is not a function
var notHoisted = function () {
console.log("bar");
};
, . ( ). , arguments.callee.
var math = {
factit: function factorial(n) {
console.log(n);
if (n <= 1) {
return 1;
}
return n * factorial(n - 1);
},
};
math.factit(3); //3;2;1;
, , name, . . , name ( ). , ( ). ( , .. ).
var foo = function () {};
foo.name; // "foo"
var foo2 = foo;
foo2.name; // "foo"
var bar = function baz() {};
bar.name; // "baz"
console.log(foo === foo2); // true
console.log(typeof baz); // undefined
console.log(bar === baz); // false (errors because baz == undefined)
() x. :
var x = function (y) {
return y * y;
};
-.
button.addEventListener("click", function (event) {
console.log("button is clicked!");
});
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-function-definitions |
Functions and function scopeFunctionfunction statementfunction* statementfunction* expressionGeneratorFunctionThis page was last modified on 29 . 2026 . by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |