new
Creates a new object using a class or a constructor function.
Available since: ES1
Syntax
new Constructor(args)Examples
Objects of built-in classes:
const date = new Date(2026, 0, 1);
const tags = new Set(['js']);
console.log(date.getFullYear(), tags.size);Output:
2026 1An instance of your own class:
class User {
constructor(name) {
this.name = name;
}
}
const anna = new User('Anna');
console.log(anna.name);Output:
AnnaNotes
Classes cannot be called without new — that throws a TypeError. But String(), Number() and Boolean() are called without new: with it they create wrapper objects that behave oddly.
See also
- class — Declares a class — a template for objects with shared methods.
- instanceof — Checks whether an object was created by a class (or a subclass).
- Date — A date and time: creating, reading parts, calculating.
- Map — A collection of key–value pairs where a key can be anything.
In the tutorial
- Classes and objects — Classes in JavaScript: declaring a class, the constructor, fields, methods, this and creating objects with new.