Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between function declarations [duplicate]

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

like image 234
m4tx Avatar asked Dec 04 '25 17:12

m4tx


2 Answers

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
  }
};
like image 179
amrfaissal Avatar answered Dec 06 '25 09:12

amrfaissal


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)?

like image 33
LPD Avatar answered Dec 06 '25 07:12

LPD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!