JavaScript new

Beginner
5 min read
Updated: Nov 2026
3 examples

Definition and Usage

The new operator creates an object, sets its prototype from the constructor, binds this inside the constructor, and returns the instance (unless the constructor returns another object).

JavaScript Syntax

JavaScript
function Point(x, y) {
  this.x = x;
  this.y = y;
}
const p = new Point(1, 2);
console.log(p.x, p.y);
Try it Editor

How It Works

  1. new Point. Creates an object.
  2. this fields. x and y are set on the instance.

Examples

Example 1 — With class

Prefer class syntax in modern code.

JavaScript
class Cat { constructor(n){ this.n = n; } }
console.log(new Cat("M").n);
Try it Editor

How It Works

  1. constructor runs with new.

Example 2 — Forgetting new

Can pollute this or throw in classes.

JavaScript
class A {}
try { A(); } catch (e) { console.log(e.name); }
Try it Editor

How It Works

  1. Class constructors require new.

Example 3 — Built-ins

new Date(), new Map(), etc.

JavaScript
console.log(new Date(0).getTime());
Try it Editor

How It Works

  1. Date constructed for epoch.

Frequently Asked Questions

Only for constructors/classes meant to create instances. Ordinary functions are called without new.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful