class vs constructor()
class and constructor() are both JavaScript Class APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. class: Defines a class. Its syntax is class MyClass { }. constructor(): Creates class instances. Its syntax is constructor(params). Example of class: class Person { constructor(name) { this.name = name } }. Example of constructor(): class Foo { constructor(x) { this.x = x } }. Read the full references for class and constructor() to see edge cases, time complexity, browser support, and the mistakes developers most often make with each. Other Class APIs worth comparing: extends, super(), static, new.target. Both belong to the Class category in the JS Reference documentation, which covers 6 entries in total. Try both in the JavaScript playground to see the behavioral difference live.