JScript functions can perform actions, return values, or both. For example, a function could display the current time and return a string that represents the time. Functions are also called global methods.
Functions combine several operations under one name, which makes code streamlined and reusable. You can write a set of statements, name it, and then execute the entire set by calling its name and passing to it the necessary information.
To pass information to a function, enclose the information in parentheses after the name of the function. Pieces of information that are passed to a function are called arguments or parameters. Some functions do not take arguments, while others take one or more arguments. In some functions, the number of arguments depends on how you are using the function.
JScript supports two kinds of functions, those that are built into the language and those that you create.
In This Section
- Type Annotation
Describes the concept of type annotation and how to use it in a function definition to control the input and output data types.
- User-Defined JScript Functions
Illustrates how to define new functions in JScript and how to use them.
Explains the concept of recursion and illustrates how to write recursive functions.