Posted By

DonovanGlover on 08/24/12


Tagged

javascript function


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

yusege
alexmensi
swapnilgg


Declaring Functions


 / Published in: JavaScript
 

URL: http://stackoverflow.com/questions/336859/javascript-var-functionname-function-vs-function-functionname

Different ways to declare functions in JavaScript.

  1. // Function Defined At Parse-Time
  2. function functionName() {
  3. console.info("Example 1 Executed.")
  4. }
  5.  
  6. // Function Defined At Run-Time
  7. var functionName = function() {
  8. console.info("Example 2 Executed.")
  9. }
  10.  
  11. // Auto-Executed Function Defined At Parse-Time
  12. (function functionName() {
  13. console.info("Example 3 Executed.")
  14. }())
  15.  
  16. // Auto-Executed Function Defined At Run-Time
  17. var functionName = (function() {
  18. console.info("Example 4 Executed.")
  19. }())

Report this snippet  

You need to login to post a comment.