JavaScript public class field

A simple tutorial on the new JavaScript Public Class Fields

In the past, to create a public class field, we would use the following syntax to instantiate the field in the constructor:

class Counter {
  constructor() {
    this.count = 0
  }
}

newClass suggestion, It can be used from Chrome 72 and Node 12, it allows us to use the following syntax:

class Counter {
  count = 0
}

Much simpler!

Download mine for freeJavaScript beginner's manual


More js tutorials: