TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
new operator creates an instance of a user-defined object type or of one of the built-in object types that possesses a constructor function. It fundamentally alters the execution context of a function call, shifting it from a standard invocation to a constructor invocation.
new keyword, the JavaScript engine executes a strict four-step internal sequence:
- Object Creation: A new, blank JavaScript object is allocated in memory.
- Prototype Linkage: The newly created object’s internal
[[Prototype]]is bound to the constructor function’sprototypeproperty. If the constructor’sprototypeis a primitive value (includingnull), the engine safely falls back to binding the[[Prototype]]toObject.prototype. - Context Binding: The constructor function is executed with the newly created object bound to the
thisexecution context. Any properties or methods added tothiswithin the constructor are attached directly to the new object. - Implicit Return: The engine evaluates the constructor’s return value. If the constructor explicitly returns a non-primitive object (e.g., an Object, Array, or Function), that object is returned, and the newly created object from Step 1 is discarded. If the constructor returns a primitive value (or returns nothing), the engine implicitly returns the newly created object referenced by
this.
new operator can be represented by the following equivalent function:
Constructor Constraints
Not all functions can be invoked with thenew operator. The engine enforces specific constraints based on the function type:
- Arrow Functions: Arrow functions cannot be used with the
newoperator. They lack the[[Construct]]internal method and do not possess aprototypeproperty. Attempting to instantiate an arrow function will throw aTypeError. - ES6 Classes: ES6
classconstructors strictly require thenewkeyword. Unlike standard functions, invoking a class constructor as a standard function (withoutnew) will throw aTypeError.
The new.target Meta-Property
When a function is executed, the engine populates a pseudo-property named new.target. This allows developers to detect at runtime whether a function was invoked via the new operator.
- If the function was called with
new,new.targetholds a reference to the constructor function or class that was initially invoked. In the context of class inheritance, if a parent class is instantiated via a subclass (e.g., viasuper()),new.targetwithin the parent constructor refers to the subclass that was initially invoked, not the parent constructor. - If the function was called via standard invocation,
new.targetevaluates toundefined.
Master JavaScript with Deep Grasping Methodology!Learn More





