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

SyntaxError: function statement requires a name - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

SyntaxError: function statement requires a name

    Syntax Error: Expected identifier (Edge)
    SyntaxError: function statement requires a name [Firefox]
    SyntaxError: Unexpected token ( [Chrome]

In this article

SyntaxError

?

(Function statement) . (Function expression) IIFE , .

vs

( ) :

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

:

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

, IIFE (Immediately Invoked Function Expression) . :

js
(function () {})();

function :

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

:

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

. function .

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

. .

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

:

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


Web Proxy Viewer  |  New URL  |  Original Page