Function with Multi Purpose

by Yubraj Pokharel

JavaScript

function add(num1, num2, num3){
	if(num2 == undefined && num3 == undefined){
  	alert(num1);
  }else if(num3 == undefined){
  	alert(num1 + num2);
  }else{
  	alert(num1 + num2 + num3);
  }
}

add(1);
add(1, 2);
add(1, 2, 3);