Question #15

Author: admin
tags: JavaScript  
The following code is executed in the browser outside the module:
const Test = function() {
  this.num = 5;
  return { num: { valueOf: function() { return 2; } } };
};

const x = Test();

const y = new Test();

console.log(x.num + y.num); // ??
What will the console output be?
2
4
5
7
10
NaN
'2[object Object]'
'5[object Object]'
'[object Object]5'
'[object Object]2'
If the constructor function has a return, then when the constructor is called, even with the new operator, the usual behavior may change.
If an object is returned in return and not a primitive value, then this object is returned.
By the way, after executing the code from this task, the num property with the value 5 was created in the window object.
Rate the difficulty of the question:
easyhard