JScript Language Elements

| Tutorial | Reference |

Functions

| Functions | Creating Your Own Functions | Returning Values |

Functions combine several operations under one name. This lets you streamline your code, because you can write out a set of statements just once, and then execute the entire set any time you want or need to, just by naming it and passing to it any parameters it needs. You've already seen several of these, if you've read through the preceding sections of this tutorial.

EXAMPLE:
var anExpression = "6 * 9 % 7";
var total = eval(anExpression);        //  Assigns the value 5 to the variable total.
This example uses the eval function, which is built into JScript.

There are many other functions also built into JScript; some of these are contained in the Math, Date, and String objects. The others are the escape and unEscape functions, and three functions that let you deal with expressions and convert strings to numeric values:

escape(aString)
unescape(aString)
eval(aString)
parseFloat(aString)
parseInt(aString,anOptionalRadix)
The first of these, escape(whatEver) and unescape(something), are used to convert characters that have special meanings in HTML code, characters that you cannot just put directly into text. For example, the angle brackets, "<" and ">", delineate tags. The escape function takes as its argument any of these special characters, and returns the escape code for the character. Escape codes consist of a percent sign (%) followed by a two-digit number. Not surprisingly, the unescape function is the exact inverse. It takes as its parameter a string consisting of a percent sign and a two-digit number, and returns a character.

For more information on these functions, please see the JScript Language Reference section.




© 1996 by Microsoft Corporation.