//ES5
function person(name,age,profession){
profession===undefined?profession="engineer":profession=profession;
this.name = name;
this.age = age;
this.profession = profession;
}
var lokman = new person('lokman',32);//In javascript no need to provide all the parameter when a function is called.
console.log(lokman);
//ES6
function person(name,age,profession='engineer'){
this.name = name;
this.age = age;
this.profession = profession;
}
var lokman = new person('lokman',32);
No comments:
Post a Comment