Javascript types of functions

Notes:

Types of JavaScript Functions:
Any function created using different ways of creating JavaScript functions, will be of one of the below mentioned type.
1. A function without parameters and without returning value
2. A function without parameters and with returning value
3. A function with parameters and without returning value
4. A function with parameters and with return value

Creating different types of functions using function declaration:
A function without parameters and without returning value:

Ex:
function wishHi()
{
document.write( “Hi” , ”<br/>” );
}
wishHi();

A function without parameters and with returning value:
Ex:
function wishHi()
{
return “Hi”;
}
document.write(wishHi());

A function with parameters and without returning value:
Ex:
function wish(what)
{
document.write( what , ”<br/>” );
}
wish(“good morning”);
wish(“good afternoon”);

Ex:
function add(num1,num2)
{
document.write( num1 + num2 , ”<br/>” );
}
add(2,2);

A function with parameters and with return value:

Ex:
function add(num1,num2)
{
return num1 + num2;
}
document.write(add(2,2));

function square(x)
{
return (x*x);
}
document.write(square(5));

Interview Questions: