-1
  (function funcName(params){
    console.log("fucName = "+params);
  });
  funcName("Function");

// i get error in chrome Uncaught ReferenceError: funcName is not defined(…)

  function funcName(params){
     console.log("fucName = "+params);
  };
  funcName("Function");

//this can run

cweiske
  • 27,869
  • 13
  • 115
  • 180
  • 1
    _i get error_ that's the difference. You might be interested in [What is the purpose of wrapping whole Javascript files in anonymous functions like “(function(){ … })()”?](http://stackoverflow.com/q/2421911/2025923), [JavaScript function declaration syntax: var fn = function() {} vs function fn() {}](http://stackoverflow.com/q/336859/2025923) – Tushar Nov 09 '16 at 03:27
  • 1
    Possible duplicate of [What is the (function() { } )() construct in JavaScript?](http://stackoverflow.com/questions/8228281/what-is-the-function-construct-in-javascript) – Dymos Nov 09 '16 at 03:29
  • thanks,i know "(function() { } )()" is Immediately-Invoked Function Expression ,but why i can not find the function – jinglong zhang Nov 09 '16 at 03:37

1 Answers1

2

The first is a "named function expression" enclosed in parentheses. Function expressions are not added to the current scope, and so you won't be able to call that function the way you are trying to do.

The second is a "function declaration". Function declarations are added to the current scope and that's why you are able to call it.

That second link should tell you everything you need to know about these two constructs.

JLRishe
  • 90,548
  • 14
  • 117
  • 150