Follow us on Facebook
Faucibus toroot menuts
A function is a piece of code that can be called anywhere in the program. The function lies idle until it is referenced or called upon to do its work. Functions are time saver because same piece of code you do not have to write again and again.
There are mainly three types of functions
1. Function without parameters
2. Functions with parameters
3. Function with return value
1. Function without argument
The function which does not have any argument is called function without argument.
As you know the main purpose of the function is re-usability.
Let’s take an example: Suppose you have a website in which you want to display current year as with copy right which will be dynamically changing as the year passes by.
For that, we can create a function inside which we will write code to display current year.
var currentTime = new Date();
year = currentTime.getFullYear();
document.write("Copyright© " + year);
The above code will generate output like this:
That means, the function is reusable.
Also, the above function is example of function without argument.