3

Possible Duplicate:
JavaScript: var functionName = function() {} vs function functionName() {}
What’s the difference in those declarations (in JavaScript)?

Is there any differences between the following function declarations:

function wtf() {
}
lol = function() {
}
omg: function() {
}

?

Regards

asked Dec 12, 2012 at 14:06
1

3 Answers 3

4

1- Is a regular function declaration.

2- You declare an anonymous function and you store it in a variable.

3- The last one is part of an object notation :

var obj = {
 omg:function(value){
 // some code here
 }
};
answered Dec 12, 2012 at 14:14
Sign up to request clarification or add additional context in comments.

Comments

4

1st one :

creates a function at page level ( global level u can say )

2nd : Assings the function to variable 'lol'

3rd: Syntax error. :P

Exactly similar to: What's the difference in those declarations (in JavaScript)?

answered Dec 12, 2012 at 14:10

6 Comments

The first one isn't necessarily global, it depends which scope it's defined in. Actually, in the example given, the second one is global, assuming the variable isn't scoped before.
@deceze: If first 2 declared inside a function: are not they exact equivalent?
@raghavv this link explains it a bit more clearly.
@raghavv Nope, try it: jsfiddle.net/UtTGG
|
0

No, it’s the quite the same thing for each of them.

answered Dec 12, 2012 at 14:09

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.