Let us start with an example.
//Code inside function
By adding function we can't use it. We need to call the function to execute the code kept inside the function. The line at the end of the above code call the function to execute it.
document.write('Welcome to plus2net');
my_fun(); // Call to function
Passing a string variable to function.
We can supply a variable to the function and use the same to process inside it
Getting return variable from function.
document.write('Welcome to ' + str);
We can input two integers to function and get the sum of the two integers as return variable to calling script. We used parseInt function to convert input
var v3= v1 + v2;
document.write('Sum of two number is ' + result);
This article is written by plus2net.com team.
| More on Loops and Variables