Css Practical 4
Css Practical 4
Experiment No: 4
Title of Experiment Develop a JavaScript to implement a function.
Theory:
Function names can contain letters, digits, underscores, and dollar signs
(same rules as variables).
Function Invocation
The code inside the function will execute when "something" invokes (calls)
the function:
Function Return
When JavaScript reaches a return statement, the function will stop
executing.
Page | 1
If the function was invoked from a statement, JavaScript will "return" to
execute the code after the invoking statement.
Functions often compute a return value. The return value is "returned" back
to the "caller":
Syntax
Example
var x = myFunction(4, 3); // Function is called, return value will end
up in x
function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}
Program:
<html>
<head>
<script type="text/javascript">
function Check()
if (a% 2==0)
else
Page | 2
document.write(a+ "number is odd");
</script>
</head>
<body>
<script type="text/javascript">
Check();
</script>
</body>
</html>
Output:
Page | 3
Page | 4
Function calling with parameter:-
<html>
<head>
<script type="text/javascript">
function Check()
if (a% 2==0)
else
</script>
</head>
<body>
</body>
</html>
Page | 5
Output:
Page | 6
Caller Program
<html>
<head>
<script type="text/javascript">
function prim(x,y)
varargs=prim.arguments;
document.write("prim caller"+prim.caller+"<br>");
for(vari=0;i<args.length;i++)
document.write("argument"+i+"is"+args[i]+"<br>");
function sec(x,y,z)
varyr = d.getFullYear();
prim(x,y,z,yr);
Page | 7
}
</script>
</head>
<body>
<script type="text/javascript">
prim(1,"two",3);
sec(4,"five",6,"seven");
</script>
</body>
</html>
Output:
Page | 8