[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Errors/Unnamed_function_statement [Back]  [Original]

SyntaxError: function statement requires a name - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

SyntaxError: function statement requires a name

JavaScript "function statement requires a name"

SyntaxError: Function statements require a function name (V8-based)
SyntaxError: function statement requires a name (Firefox)
SyntaxError: Function statements must have a name. (Safari)

SyntaxError

IIFE

function function

js
function () {
  return "Hello world";
}
// SyntaxError: function statement requires a name

function

js
const greet = function () {
  return "Hello world";
};

IIFE

js
(function () {
  // 
})();

js
function Greeter() {
  german: function () {
    return "Moin";
  }
}
// SyntaxError: function statement requires a name

js
function Greeter() {
  function german() {
    return "Moin";
  }
}

function

js
const greeter = {
  german: function () {
    return "Moin";
  },
};

js
const greeter = {
  german() {
    return "Moin";
  },
};

js
promise.then(
  function () {
    console.log("success");
  });
  function () {
    console.log("error");
}
// SyntaxError: function statement requires a name

js
promise.then(
  function () {
    console.log("success");
  },
  function () {
    console.log("error");
  },
);


Web Proxy Viewer  |  New URL  |  Original Page