April 21, 2009

0 The return statement in JavaScript


The return statement is used to specify the value that is returned from the function.

So, functions that are going to return a value must use the return statement.

Tutorial

The function below should return the product of two nos (a and b).

function prod(a, b)
{
x=a*b
return x
}


When u call the function above, you must pass along two parameteres:

product=prod (2, 3)

The return value from the prod() function is 6, and it will be stored in the variable called product.

Tutorial

<html>
<head>
<script type="text/javascript">
function displaymessage ( )
{
alert ("Hello World")
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onClick="displaymessage ()">
</form>
</body>
</html>





0 comments:

Post a Comment

Blogger Themes

 
Powered by Blogger