4. Custom Functions

4.2. Function as an expression


          Another way to define a function in JavaScript is as an expression:  The most common syntax would be to create an unnamed function and assign it to a variable.  Below is a rewrite of the same function in the previous section using this method below:

var addTwoNumbersv3 = function(num1, num2)
{     
     return num1 + num2; 
}

       

          In this case addTwoNumbersv3 is a variable not a function name, and represents the value that is being returned by the unnamed function, thus:

document.write(addTwoNumbersv3(3, 6)) ;

will still write on the browser the number 9.