1.

What Is The Difference Between The Function Declarations Below?  var Foo = Function(){ // Some Code  }; Function Bar(){ // Some Code  }; 

Answer»

The main difference is the FUNCTION foo is defined at run-TIME whereas function BAR is defined at parse time. To understand this in better way, let's take a look at the code below:

Run-Time function declaration 

 Another advantage of this first-one way of declaration is that you can DECLARE functions based on certain conditions. For example:

 However, if you try to run similar code USING the format below, you'd get an error:

The main difference is the function foo is defined at run-time whereas function bar is defined at parse time. To understand this in better way, let's take a look at the code below:

Run-Time function declaration 

 Another advantage of this first-one way of declaration is that you can declare functions based on certain conditions. For example:

 However, if you try to run similar code using the format below, you'd get an error:



Discussion

No Comment Found