1

Possible Duplicate:
Javascript: var functionName = function() {} vs function functionName() {}

Is there any difference between these two ways of declaring a function?

Community
  • 1
  • 1
Kent
  • 2,774
  • 2
  • 22
  • 42
  • 1
    The second one, I think you meant `function x(a,b,c){}`, because `function(a,b,c){}` will just simply cause a `SyntaxError` when used in *statement context*, see [this](http://stackoverflow.com/questions/1634268/explain-javascripts-encapsulated-anonymous-function-syntax) and [this possible duplicate](http://stackoverflow.com/questions/336859/javascript-var-functionname-function-vs-function-functionname). – Christian C. Salvadó Apr 22 '11 at 07:13
  • thanks, I didn't see that post when I posted this one :( – Kent Apr 22 '11 at 08:42

2 Answers2

3

They are both anonymous functions, only one is assigned to a variable named x.

I think you may be trying to refer to what is known as function expressions and function declarations.

alex
  • 438,662
  • 188
  • 837
  • 957
1

x = function(a, b, c){} assigns the function to the alias x so you would execute it using x(a, b, c). The second is an anonymous function that would not be accessible after the place that it was declared as it is not assigned to anything.

detaylor
  • 6,836
  • 1
  • 25
  • 44