4.10 VARIABLES AND FUNCTIONS

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.