References

Beginner-friendly references for web development, with live, editable examples.

The JavaScript new operator

Operator JavaScript All modern browsers Updated
Quick answer

The new operator creates an instance from a class or constructor function. const d = new Date(), const m = new Map(). It builds a fresh object, links it to the constructor's prototype, runs the constructor with this bound to the new object, and returns it.

Overview

new builds an object from a constructor. You've used it with built-ins — new Date(), new Map(), new Set(), new Error() — and with your own classes: new User("Ada"). It's the bridge between a blueprint (the class) and an actual instance you can use.

Under the hood, new does four things in order: it creates a fresh empty object; links that object's prototype to the constructor's prototype (so the instance inherits its methods); calls the constructor with this bound to the new object (so the constructor can set up properties); and returns the new object automatically. Understanding those steps explains why this inside a constructor refers to the instance.

A couple of cautions. Forgetting new with a constructor that relies on this can cause bugs (in strict mode, this is undefined and you get an error) — modern classes guard against this by throwing if you call them without new. And arrow functions can't be used with new at all. For plain data you usually don't need new — an object literal {} or array literal [] is simpler than new Object() or new Array().

Syntax

new Constructor(arguments)

const now = new Date();
const map = new Map();
const user = new User("Ada");  // your own class

Example

Live example
<pre id="out" style="font:15px ui-monospace,monospace"></pre>
<script>
  class Point {
    constructor(x, y) { this.x = x; this.y = y; }
    toString() { return '(' + this.x + ', ' + this.y + ')'; }
  }

  const p = new Point(3, 4);

  document.getElementById('out').textContent =
    'point: ' + p.toString() + '\n' +
    'is Point? ' + (p instanceof Point); // point: (3, 4) / is Point? true
</script>

Best practices

  • Use new to instantiate classes and built-in constructors like Date, Map and Set.
  • Don't use new for plain data — literals {} and [] are simpler than new Object()/new Array().
  • Remember arrow functions can't be constructors — use a regular function or class.
  • Modern classes throw if called without new, which catches a common mistake.

Frequently asked questions

What does the new operator do?
It creates a new object, links it to the constructor's prototype, runs the constructor with this bound to the new object, and returns it.
What happens if I forget new?
With a constructor that uses this, you can get errors or wrong behavior. Modern classes throw a TypeError if called without new.
Can I use new with an arrow function?
No. Arrow functions can't be constructors. Use a regular function or a class.
Do I need new for objects and arrays?
No. Use the literals {} and [] — they're simpler and faster than new Object() or new Array().