I am trying to add a instance inside a function in javscript where i have observed the following behavior
function Calculator () {
this.mm = 66;
return 2 ;
}
var calculator = new Calculator();
console.log(' --> '+calculator.mm); <<< gives output of 66
But the below code
function Calculator () {
this.mm = 66;
return {} ;
}
var calculator = new Calculator();
console.log(' --> '+calculator.mm); <<< gives me undefined
I just want to know what different does returning an object from a primitive datatype make to a function . In other words why am i getting undefined here and not 66.