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

Chapter 17. Introduction to JavaScript > Creating Functions in JavaScript

Creating Functions in JavaScript

A function can be thought of as a mini-program within your script. Generally, a function is designed to accomplish one particular task and then return a value to the main body of the script. Functions start by being passed a particular value. That value is then used in calculations or as part of a procedure. Then, in most cases, the function will return a new value to the body of the script, where something else may or may not happen.

Although it’s perfectly possible to have an entire script in the body of your document (and you will, occasionally), you’ll find that this sort of procedural programming is both wasteful and limited. By breaking your scripts into functions and function calls, you gain two advantages.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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