Tags: "es6-class", "javascript-object", "syntax", access_time 1-min read

Edit this post on Github

When You New a Class in JavaScript?

Created: February 13, 2018 by [lek-tin]

Last updated: February 13, 2018

Here is an example of instantiating a class using the new operator:

class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
const asian = new Person('Alice', 25);

As you can see from below, asian is not a class, it is instead, an object:

[object Object] {
  age: 25,
  name: "Alice"

The values of asian are set by the constructor of the Person class.