Skip navigation

Monthly Archives: February 2009


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


in which case it will return NaN because you can’t add undefined values.

Even you can call 


in which case it will return 5, ignoring 4 and 5.

OOPs guys will call it as FUNCTION OVERLOADING.


Function as Class definition

function Shape(width, height) {
  this.width = width;
  this.height = height;

Now you can create object using new keyword like

var objShape = new Shape(5,4);

Function as class method

var Shape = {width:4,height:5} = showWidth;

function showWidth(){

function IllRetun() {
if(IllRetun()) alert(IllRetun()) else alert(‘bad return’)

You will be alerted with bad return; Lesson: Don’t forget semicolon;