Calling a Function in new Function
In JavaScript, a user can call a Function from another Function such as:
In JavaScript, a user can call a Function from another Function such as:
<script type=”text/javascript”>
function firstCandy()
{
document.write (“ Hersheys”);
}
function secondCandy()
{
document.write (“ Toblerone”);
}
function goodCandy(){
firstCandy();
secondCandy();
}
goodCandy();
</script>
Output:
Hersheys Toblerone
Calling a Function within Function:
When we try calling the Functions within each other, it prints results like never ending cycle. It is bad programming.
<script type=”text/javascript”>
function firstCandy()
{
document.write (“ Hersheys”);
secondCandy();
}
function secondCandy()
{
document.write (“ Toblerone”);
firstCandy();
}
firstCandy();
</script>
Output:
Hersheys Toblerone Hersheys Toblerone Hersheys Toblerone Hersheys Toblerone
Hersheys Toblerone...
No comments:
Post a Comment