February 2018
Intermediate to advanced
298 pages
8h 22m
English
The constructor method, by default, returns the new instance if there is no return statement in it. If there is a return statement, then any value in the return statement is returned. This might seem a little weird if you're coming from a language like C++ as you cannot usually return any value from the constructor there.
Here is an example to demonstrate this:
class myClass { constructor() { return Object.create(null); } } console.log(new myClass() instanceof myClass); //Output "false"
Read now
Unlock full access