Function and procedure structure/Parameters
The purpose of this week’s blog is to discuss how procedures and functions are structured in JavaScript. They are essentially the same thing and are a fundamental building block of most JavaScript programs. A function groups together (using curly braces) a set of statements under a subroutine named by the programmer. At any time in the program that you need to perform the task that this subroutine accomplishes all you have to do is “call” the function. However, first you must create the function and an ordinary function is structured like this:
function_name(parameters) {
JavaScript commands
}
The functions are placed in the HTML file in the SCRIPT tags before the function call. JavaScript allows you to create as many of these subroutines as you need in your program along with all the subroutines it offers in its standard library to complete your objectives.
If you need to reuse a function in another program you can just copy and paste it from your previous code.
The parameters in between the paranthesis above are what the program uses, or needs, to complete the task it is designed for. You may pass as many parameters as necessary to complete the job. If you do pass multiple parameters you must make sure that each variable type matches in the function declaration as in the function call (like if the function is expecting an int, int, float you have to pass variables of those data types in that specific order in the call otherwise an error occurs). Basically, there is nothing too significantly different from Java or C++ when it comes to parameter passing in JavaScript. The end.
0 Comments:
Post a Comment
<< Home