Here are some of the ways that variables and functions can be declared.

   var n = 1;
   function f1() {}               //function statement
   (function f2() {});            //function expression
   (function (f3) {} (param));    //function with parameter

At the outset it appears that functions in JavaScript are no different from functions in other programming contexts like C or C++ or Java. It is true that they are referred in the same context in the sense that a function is a block of code defined once but reused several times across. JavaScript also supports the concept of recursive functions. They are defined and invoked in much the same way as in other languages. However, there are stark differences in JavaScript which makes this language extremely ...

Get Web Technology: Theory and Practice now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.