Wednesday, 11 December 2013

Return Values In JavaScripts

Return Values In JavaScript
The return statement in JavaScript. As in article such as function in JavaScript , Multiple parameters with functions in JavaScript we had seen statement such as document.write which output something on the screen or alert which output something on the screen as a popup box. Sometimes you want statement return a value to you. So, this is specially useful whenever you making ancalculation and you passing two numbers as a parameters. For example 20 and 10 you can say multiply this together multiplies and returns the value to you. In another words it performscalculation and returns the answer to you. When you performscalculation you need answer a return value can be called answer. Let see example

code for return statement in JavaScript

the return values
the return values (Screenshot1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
<html>
<head>
</html>
<body>
 
<script type="text/javascript">
<span id="IL_AD5" class="IL_AD">function</span> addNumbers(a,b) {
var c = a+b;
return c;
 
}
 
document.write(addNumbers(3,6));
</script>
 
</body>
</html>
<pre>
Output
the return values
the return values (Screenshot2)
Above code we had function name add Numbers we had two variables a and b. We perform addition of two numbers. we had pass values to a and b by 3 and 6. Now return value just say to thefunction that the c is the return value of addition of a and b. Its justreturn the value to the c. The return value will return only the value which is perform by any functions such as here we had used for adding two numbers and return value to the variable c.

No comments:

Post a Comment