Code:
// Undefined return value.
function A() {
this.name = 'Name';
return;
}
// Reference to instance.
function B() {
this.name = 'Name';
return( this );
}
// String return value.
function C() {
this.name = 'Name';
return( "string" );
}
// Number return value.
function D() {
this.name = 'Name';
return( 123 );
}
// New object return value.
function E() {
this.name = 'Name';
return( { foo: "bar" } );
}
// New array return value.
function F() {
this.name = 'Name';
return( [ "foo", "bar" ] );
}
// New instantiation return value.
function G() {
this.name = 'Name';
return( new A() );
}
// Native "object" return value -- this one would be the same
// for Number, Boolean, and String.
function H() {
this.name = 'Name';
return( new Number( 123 ) );
}
function I() {
this.name = 'Name';
return function() {
return 5;
}
}
// -------------------------------------------------- //
// -------------------------------------------------- //
// See what reference we have as a result of instantiation.
console.log( new A() );
console.log( new B() );
console.log( new C() );
console.log( new D() );
console.log( new E() );
console.log( new F() );
console.log( new G() );
console.log( new H() );
console.log( new I() );
Output:
A {name: "Name"}
B {name: "Name"}
C {name: "Name"}
D {name: "Name"}
{foo: "bar"}
(2) ["foo", "bar"]
A {name: "Name"}
Number {123}
ƒ () {
return 5;
}