Chapter 5. Arguments: passing data to functions
This chapter covers
- Defining functions with parameters, ready to accept data
- Calling functions, passing in data with arguments
Functions are an essential means of organization; you write them once and use them many times. But so far, your functions have been tied to the values of variables around them. It’s time to set your functions free, letting them name their own variables and passing them the data they need.
5.1. Function reuse and versatility
The functions you’ve used up to now have relied on variables declared and assigned values elsewhere in the program. In the following listing, the showMessage function relies on a variable called message, declared outside the function definition. ...
Get Get Programming with JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.