Chapter 6. Return values: getting data from functions

This chapter covers

  • Returning information from functions
  • The return keyword
  • Experimenting at the console prompt

In chapter 4 you discovered how functions can increase your efficiency by allowing you to write code once but use it many times. In chapter 5, you made functions much more flexible by passing them information with each call; a function can act in different ways and produce different outputs depending on the arguments you give it. In this chapter you give functions the chance to talk back by returning the results of their work. You also call functions directly at the console prompt to investigate the values they return.

6.1. Returning data from functions

It’s often useful ...

Get Get Programming with JavaScript now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.