Skip to content

Constructor Context

When a function is used as a constructor with the new keyword, this refers to the newly created instance.

function Person(name) {
this.name = name;
}
const alice = new Person("Alice");
console.log(alice.name); // Alice