basically lets check all the code:
var MyObject1 = function (a, b) {}
this is a function assignation, you can redefine this as
function MyObject1(a,b){}
lets continue with the return statement of the function
return { ... }
here you are returning an Object so it would be what you will have assigned on the variable that you are assignating with the return of your function.
let obj1 = MyObject1(1, 2)
here we can see that you are assigning the return of the MyObject1(1,2) to the obj1 variable, and the return is an object that you build dynamically each time that you call MyObject1.
and at the end you ask why obj1.myA; is 1 right? this is easy, you created and object with the following properties based on the parameters of the object construction, in this case (1, 2):
{
myA: 1,
myB: 1,
hello: function()
}
this it is clear why the value of obj1.myA is 1.
var MyObject1 = function(a, b) {
return {
myA: a,
myB: b,
hello: function() {
return "Hello !";
}
};
};
let obj1 = MyObject1(1, 2);
console.log(obj1);
console.log(obj1.myA);