The return keyword is not mandatory when using a function as a constructor with “new”. If you don’t explicitly return anything, JavaScript automatically returns the newly created object.
function payload(){
this.orderNum = “SO-USA-19388”;
this.location = “America”;
this.totalAmount = 3900;
return “Hello”;
}
let recordData = new payload();
console.log(recordData.orderNum); // Output: SO-USA-19388
console.log(recordData.location); // Output: America
console.log(recordData.totalAmount); // Output: 3900
If there is a return in the function its ignored.
return “Hello”; // Ignored