O'Reilly logo

Web Technology: Theory and Practice by M. Srinivasan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required