liveBook · Manning

New keyword

Also called new operator

In JavaScript, new is an operator that creates an object instance by invoking a constructable function or class as its constructor.

How 4 Manning books explain it

Secrets of the JavaScript Ninja, Second Edition

A JavaScript operator that creates an object instance and invokes a constructor function with that object as its this value.

How it is used
Creates and initializes object instances by invoking functions as constructors.
How deep it goes
Explains object creation, `this`, prototype linkage, and return-value exceptions through contrasting calls and examples.
Examples
Contrasts ordinary and constructor calls, constructs two objects with methods, and tests primitive and object returns.
What you can do after
Build it from scratch: initialize instances with `new` and make methods available through a constructor's prototype.

Read how Secrets of the JavaScript Ninja, Second Edition explains new keyword →

Secrets of the JavaScript Ninja, Third Edition

The new operator invokes a constructable function, creates an object for its this value, and returns the constructed object subject to explicit-return rules.

How it is used
Invokes a constructor to initialize an object with that object as the function’s `this` value.
How deep it goes
Explains object creation, `this`, return behavior, and prototype inheritance without detailing lower-level runtime implementation.
Examples
Uses Ninja constructors, instance methods, and a prototype-defined method to demonstrate construction and inheritance.
What you can do after
Build it from scratch by invoking a constructor to initialize objects and inherit prototype methods.

Read how Secrets of the JavaScript Ninja, Third Edition explains new keyword →

JavaScript in Depth

A JavaScript operator that creates an object, links its prototype, invokes a constructor with that object as this, and determines the expression result from the constructor return value.

How it is used
Explains construction as a mechanism for reasoning about prototypes, this binding, constructor returns, and surprising instance behavior.
How deep it goes
Traces four construction steps and return selection, then stops short of detailed runtime implementation beyond internal prototype and binding concepts.
Examples
Uses Gadget, simulated construction, object-returning constructors, primitive-returning constructors, and new.target logging.
What you can do after
Diagnose unexpected instances by tracing prototype linkage, constructor this, return replacement, and construction detection.

Read how JavaScript in Depth explains new keyword →

The Joy of JavaScript

The JavaScript operator keyword that creates a new object instance by invoking a constructor function or class.

How it is used
Instantiates constructor-based objects and enables shared prototype behavior.
How deep it goes
Explains prototype links, constructor references, method sharing, and safeguards against improper calls.
Examples
Uses Transaction and HashTransaction instances, shared methods, TypeErrors, new.target, and Object.create prototype configuration.
What you can do after
Apply it via constructor functions to create instances with shared prototype methods and safer invocation behavior.

Read how The Joy of JavaScript explains new keyword →

Also covered in

What to know first

Related concepts

Questions about new keyword

What is new keyword?

In JavaScript, new is an operator that creates an object instance by invoking a constructable function or class as its constructor.

Which Manning books explain new keyword?

Secrets of the JavaScript Ninja, Second Edition, Secrets of the JavaScript Ninja, Third Edition, JavaScript in Depth and The Joy of JavaScript.

What should I know before learning new keyword?

Manning books that teach new keyword usually introduce this, object, function and arrow function first.

What is new keyword a kind of?

New keyword is a kind of keyword. A language-defined word or token with a predefined syntactic or semantic role, which may be restricted from use as an ordinary identifier.

What is new keyword also called?

New keyword is also called new operator.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.