[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/function [Back]  [Original]

- JavaScript | MDN

MDN Web Docs

View in English Always switch to English

20157

function

Function

let function_expression = function [name]([param1[, param2[, ..., paramN]]]) {
   statements
};

ES2015

name

anonymous

paramN

255

statements

function expressionfunction statementfunction nameanonymous functions IIFEImmediately Invoked Function Expression

(Function expression hoisting)

JavaScript

js
notHoisted(); // TypeError: notHoisted is not a function

var notHoisted = function () {
  console.log("bar");
};

arguments.callee

js
var math = {
  factorial: function factorial(n) {
    if (n <= 1) return 1;
    return n * factorial(n - 1);
  },
};

name name name name name

js
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

js
var x = function (y) {
  return y * y;
};

js
button.addEventListener("click", function (event) {
  console.log("button is clicked!");
});

ECMAScript 2027 LanguageSpecification
# sec-function-definitions


Web Proxy Viewer  |  New URL  |  Original Page