Chapter: Internet & World Wide Web HOW TO PROGRAM - The Ajax Client - JavaScript: Functions

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail

Programmer-Defined Functions

Functions allow you to modularize a program.

Programmer-Defined Functions

 

Functions allow you to modularize a program. All variables declared in function definitions are local variables—this means that they can be accessed only in the function in which they are defined. Most functions have a list of parameters that provide the means for communicating information between functions via function calls. A function’s param-eters are also considered to be local variables. When a function is called, the arguments in the function call are assigned to the corresponding parameters in the function definition.

 

There are several reasons for modularizing a program with functions. The divide-and-conquer approach makes program development more manageable. Another reason is soft-ware reusability (i.e., using existing functions as building blocks to create new programs). With good function naming and definition, programs can be created from standardized functions rather than built by using customized code. For example, we did not have to define how to convert strings to integers and floating-point numbers—JavaScript already provides function parseInt to convert a string to an integer and function parseFloat to convert a string to a floating-point number. A third reason is to avoid repeating code in a program. Code that is packaged as a function can be executed from several locations in a program by calling the function.


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail


Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.