When I explicitly return an object (or something that derives from Object) from a constructor (new) it ignores the newly created object instance and returns what I told it to, but when I return a primitive data type like a number or a string it ignores my explicit return and returns the new instance. Does anyone know why this is? I dont think its a bug in the JS engine because I tried it in firefox, safari, and chrome and it all behaves the same.
function Fun1(){
return {Hats: 5};
}
Fun1(); // => {Hats: 5};
new Fun1(); // => {Hats: 5};
function Fun2(){
return 5;
}
Fun2(); // => 5;
new Fun2(); // => Fun2 {};