| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/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 7.
function (expression) .
const getRectArea = function (width, height) {
return width * height;
};
console.log(getRectArea(3, 4));
// Expected output: 12
var myFunction = function [name]([param1[, param2[, ..., paramN]]]) { statements };
name. (anonymous) , . .
paramN(argument) .
statements(statement).
(function expression) function (syntax) ( function ). function , . IIFE ( ) . .
console.log(notHoisted); // undefined
//even the variable name is hoisted, the definition wasn't. so it's 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 . , name ( ) . name ( ) . (arrow functions) ( ).
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;
};
callback :
button.addEventListener("click", function (event) {
console.log("button is clicked!");
});
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-function-definitions |
Arrow functionsFunctions and function scopeFunctionfunction statementfunction* statementfunction* expressionGeneratorFunctionasync functionasync function expressionThis page was last modified on 2026 7 15 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 |