Function B (a) {this.a = a;} an interview question about constructor instantiation

function B(a) {  
    this.a = a;  
}  

console.log(new B());   // B{ a:undefined }

output new B (), this is not the output is the return value of the B function? If there is no return value, the result should be undefined, why is the output of the function itself?

May.22,2021

I tried and did not output the function itself.


new operator
these are all basic things
using the new operator is definitely not the same as the usual function call


.

conclusion: the output is not the function itself, but the object of type B

you need to know what new does:
(1) create a new object;
(2) assign the scope of constructor B to the new object (so this points to the new object)
(3) execute the code in the constructor (add properties to the new object);
(4) return the new object.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eaf24e-47ff4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eaf24e-47ff4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?