CASE 1:
function Test(name){
var privateName = name;
this.getName = function(){
return privateName;
}
}
var name = new Test("unknown");
console.log(name.getName())
CASE 2:
function getName(pName){
var name = pName;
return name;
}
var name = getName("unknown")
console.log(name)
It seems both are doing the same thing returning the name passed to the function. Then what is the difference between the two implementations? What are we trying to achieve in CASE 1?