function add(x, y) {
var total = x + y;
return total;
}
- The
returnstatement is optional. - If no return statement is used (or an empty return with no value), JavaScript returns
undefined. - The named parameters turn out to be more like guidelines than anything else. You can call a function without passing the parameters it expects, in which case they will be set to
undefined. - alert(add());
We can just call without any parameters
add();
in which case it will return NaN because you can’t add undefined values.
Even you can call
add(2,3,4,5);
in which case it will return 5, ignoring 4 and 5.
OOPs guys will call it as FUNCTION OVERLOADING.