JavaScriptIntermediate#oop#es6

What is the difference between an ES6 class and a constructor function?

Classes are syntactic sugar over prototypes, but they are not hoisted for use, always run in strict mode, must be called with new, and support extends/super and #private fields.

Example
class Animal {
  #id = 1;
  constructor(name){ this.name = name; }
  speak(){ return `${this.name} speaks`; }
}
class Dog extends Animal { speak(){ return super.speak() + ' woof'; } }

Related Questions

1
JavaScriptAdvanced#event-loop#async

Explain the event loop.

Open
2
JavaScriptAdvanced#event-loop#async

What are microtasks and macrotasks?

Open
3
JavaScriptIntermediate#async#promises

What is a Promise and what are its states?

Open