• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 15. Combining Statements into Fu... > Retrieving Results Using Return Valu...

Retrieving Results Using Return Values

Sometimes, you want a function not only to perform a task but also to return a value to you. For instance, if you write a function to double numbers, you don’t just want it to double the numbers; you want it to pass the doubled numbers back to you so that you can do something with them. Functions supply return values using a return statement. A return statement with a return value returns that value to the caller, as in the following example, in which a function returns twice the value passed to it:

function doubleIt(numberToBeDoubled) { 
     return numberToBeDoubled * 2; 
} 


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint