Function is just way to reuse the code which can be called anywhere in the program.
Definition : A javascript function is a block of code designed to perform a perticular task.
Note : To define a javascript function, use the function keyword followed by name & set of paraemeter.
Syntax of function :
<script type = "text/javascript">
function function_name(function parameter)
{
function body
}
</script>
Example : In this example we will call the function from a button
<html>
<head>
<title> Welcome to learing nation</title>
<script type = "text/javascript">
function chandan()
{
alert("i have been called");
}
</script>
</head>
<body>
<input type = "button" value = "Submit" onclick = "chandan()">
</body>
</html>
Output : i have been called.
Function Return : Use the return statement to return a value
Example : In this example first function will return the value to the second function :
<html>
<head>
<title> Welcome to learing nation</title>
<script type = "text/javascript">
function chandan(a,b)
{
var c = a * b;
return c;
}
function csc()
{
var x = prompt("Enter your first number");
var y = prompt("Enter your second number");
var z = chandan(x, y);
document.write("your answer is :" +z);
}
</script>
</head>
<body>
<input type = "button" value = "Submit" onclick = "csc()">
</body>
</html>
Free online Java, Python, Selenium , API Testing etc. tutorials for beginners , Intermediate, Experties
Cross_Column
Subscribe to:
Post Comments (Atom)
Few More
Free JSON Compare Tool Online (Find Differences Instantly)
Free JSON Compare Tool Online (Find Differences Instantly) Use this free JSON Compare Tool to quickly find differences betwe...
-
Key Points in mobile application testing First of all specify that whethear it is a platform dependent or browser dependent. Plat...
-
What is Test Strategy? Plan to use the available resources to achieve objective effectively. Note :- Test Strategy is a part of test plan....
-
For Video : CLICK HERE What is Casting ? All casting really means is taking an Object of an particular type and "turn...
No comments:
Post a Comment