Well, functions are very interesting and can be used in various ways. Let’s understand another kind of functions in the next video.
The return statement in a function is optional. If a function does not return anything, it returns undefined by default.
A function can be declared without a name and its body can become the value of a variable. In short, a variable can store a function. Such functions are called anonymous functions because they do not have any name of their own. The syntax of such a function is:
var x = function(){ // function code here } x();
The anonymous functions are invoked using the name of the variable their function body is assigned to.