|
A function is a block of code with a defined
name that might or might not take one or more arguments. Functions
are called by name, which takes the following form: foo(bar);
The parentheses encloses any arguments that the function might
take. In this instance the function named foo takes one argument
named bar. Function can also return values, although they
do not necessarily have to. You don't necessarily have to
do anything with these return values, but they usually return
a value for a good reason, so it's best not to ignore them.
Some of the important built-in function used in JavaScript are given below:
| Functions |
Description |
| Escape(charstring) |
Returns the
conversion of charstring into a form that displays in the browser without HTML markup. |
| Eval(codestring) |
Evaluates codestring
as JavaScript code, returning anthing that Javascript returns. |
| IsName(numvalue) |
Returns true
if numvalue is not a number, otherwise returns false--- used wit parseFloat and parselint. |
| ParFloat(numstring) |
Return numstring
converted to an float, if it cannot be converted, returns the reserved value NaN. |
| Parsient(numstring) |
Return numstring
converted to an Integer, if it cannot be converted, returns the reserved value NaN. |
| Unescape(charstring) |
Returns the
conversion of charstring back into a form that displays
in the browser with HTML markup (the oppositer or escape). |
|
Example :
<HTML>
<HEAD>
</HEAD>
<BODY>
<SCRIPT language = "JavaScript">
var
addmeval = "2+2";
addmeval = evalu(addmeval);
document.write(addmeval);
</SCRIPT>
</BODY> </HTML>
You can create your own function in JavaScript.
A function is defined by combining a function statement and
a block of code to associate with that function. The function
statement consists of the word function, followed by parentheses
containing the name of the function.
Syntax :
function functionname(argument)
{
Block
statement
. }
Example :
function output(theText) {
theText = eval(theText);
document.write(theText); }
| Returning Values from Function |
Data can be returned from a function by
using the keyword return, followed by the data to be returned.
Example :
The following simple function takes a number
and returns the square of that number to the calling expression:
function square(inNum)
{ return(inNum * inNum); }
Copyrights : Layout Galaxy All Rights Reserved
No part of this tutorial may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, electrostatic, magnetic tape, mechanical or otherwise, without prior permission in writing from Layout Galaxy.
|
|