In Javascript, what excutes first: Class Properties or the Constructor?

November 29, 2020

What executes first? The Properties or the Constructor?

In most languages its the Properties first, but with how javascript doesn’t conform to normal OOP and instead uses a prototypal inheritance model I wanted to double check.

As per usual, when I test things out in js I’m either using the browser console or Quokka the Vscode extension.

I wrote this small script out which uses a generator (something I don’t use much).

  function* when(){
    let i = 0;
      yield i;
  const w = when()
  const next = () =>

  class Test{
    prop = next()
      this.constr = next()
  const t = new Test()

The output proves that like most other languages the props get evaluated first and the constructor second.

Object { prop: 0, constr: 1 }