Skip navigation

 

function add(x, y) {
    var total = x + y;
    return total;
}
  • The return statement 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.

Advertisements

One Trackback/Pingback

  1. […] Also check another post on the same topic at https://vkanakaraj.wordpress.com/2009/02/27/function-parameter-shock/ […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: