What new really does: constructors, instanceof and Object.create
new creates an object, links it to the constructor's prototype, runs the constructor, and returns the object. Build new and instanceof yourself.
Comes up in: JavaScript, Coding
Learn#
Aditya forgets new and writes const u = User("Asha"). In strict code he gets a TypeError. In an old sloppy script, name silently lands on the global object, and u is undefined. Knowing what new does explains both.
A constructor is a function meant to be called with the new operator. new User("Asha") does four things:
- Creates an empty object.
- Links it to
User.prototype. - Calls
Userwiththisset to that object. - Returns the object — unless
Userreturned an object of its own.
Returning a primitive from a constructor is ignored; returning an object replaces the new one.
User.prototype.constructor points back to User, so every instance can find its constructor.
function User(name) { this.name = name; }
User.prototype.hi = function () { return "Hi " + this.name; };
const u = new User("Asha");
console.log(u.hi(), Object.getPrototypeOf(u) === User.prototype, u.constructor === User);
function Weird() { this.a = 1; return { b: 2 }; }
function Prim() { this.a = 1; return 42; }
console.log(JSON.stringify(new Weird()), JSON.stringify(new Prim()));
console.log(u instanceof User, u instanceof Object, [] instanceof User);Output (verified)
Hi Asha true true
{"b":2} {"a":1}
true true falseinstanceof walks the value’s prototype chain looking for User.prototype.
new object
- { }
its prototype
- —
this inside User
- —
Step 1: new makes an empty object.
Read the steps as text
- Step 1: new makes an empty object.
- Step 2: it links the object to User.prototype, where hi() lives.
- Step 3: it calls User with this = the new object. The body adds name.
- Step 4: User returned nothing, so new returns the object.
Predict#
Predict first
function A() {} const a = new A(); A.prototype = { fresh: true }; Is a instanceof A now?
instanceof does not remember who created an object. It checks whether the current A.prototype appears in a’s chain. Replacing A.prototype breaks the match for old objects.
Interview angle#
Say it like this — about 30 seconds
“
new F(args)creates an empty object and sets its prototype toF.prototype. It callsFwiththisbound to that object, then returns it — unlessFreturns an object, which wins.instanceofwalks the left side’s prototype chain looking forF.prototype.Object.create(proto)does the linking step without calling a constructor, andObject.create(null)gives an object with no prototype at all — a clean dictionary.”
Follow-up Are classes just syntactic sugar over constructor functions?
new. Their bodies are strict, and they are in the TDZ before their line. Methods are not enumerable. Derived classes must call super() before using this.Follow-up Implement instanceof.
F.prototype return true; move to its prototype; stop at null and return false. Primitives return false.Follow-up Why use Object.create(null)?
toString or __proto__, so any string is safe as a key.Practice#
Timed, like the real round
Implement myNew and myInstanceof in 20 minutes, without using new or instanceof for the main logic.
Done when
myNew(User, "Asha")returns an object linked toUser.prototypewithnameset; an object returned by the constructor wins, a primitive does not.myInstanceofmatchesinstanceoffor instances, arrays,Object.create(null)and primitives.
Remember#
Try to answer each card before you open it. Then add them to your reviews.
What are the four steps of new F()?
Create an object, link it to F.prototype, call F with this = it, return it (unless F returns an object).
How does instanceof work?
It walks the value's prototype chain looking for F.prototype.
What does Object.create(null) give you?
An object with no prototype — a clean dictionary.
What happens if a constructor returns an object?
new returns that object instead of the newly created one.
Go deeper
Four layers. Stop at the one your interview needs; each ends with a quick check.
The core ideaEvery round
new = create, link to F.prototype, run F on it, return it. instanceof = is F.prototype somewhere in the chain?
Check yourself: What does instanceof compare against?
The constructor's current prototype property.
How it works underneathSenior rounds
new calls the function’s [[Construct]], which uses OrdinaryCreateFromConstructor to make the object from F.prototype Source: ECMA-262: OrdinaryCreateFromConstructor. instanceof first checks F[Symbol.hasInstance], then falls back to walking the chain Source: ECMA-262: InstanceofOperator.
Check yourself: What does instanceof check first, before walking the chain?
Whether the right side has a Symbol.hasInstance method.
Edge cases and trapsWhere people slip
Each window or iframe has its own built-ins. So an array from an iframe fails instanceof Array; use Array.isArray. Object.create(proto, descriptors) also takes property descriptors, like { id: { value: 1, writable: false } } (JS.06.01).
Check yourself: Why can instanceof Array fail for an array from an iframe?
Each window or iframe has its own Array.prototype.
In productionStaff-level answers
For user-controlled keys, prefer Map, or Object.create(null), so keys like __proto__ or constructor cannot collide with inherited ones. Use Array.isArray and duck typing across realms, and classes (JS.04.03) instead of hand-written constructor functions in new code.
Check yourself: Name one safe alternative to a plain object as a dictionary.
Map, or Object.create(null).
Finished the five steps? Mark it, and its cards join your reviews.
Last checked 2026-10-31. Spot a mistake? Use “Report an error” below — fixes are listed on the corrections page.
Interview questions this answers
- What exactly does the
newkeyword do? - Are JavaScript classes just syntactic sugar? What is different from constructor functions?
- How does
instanceofwork? Implement it. - What does
Object.create(null)give you and why use it?