How to declare class attributes easily?

class Autobot {
  name = 'Optimus Prime';
  fraction = 'Autobots';

const transformer = new Autobot();

// output: I am Optimus Prime and leader of the Autobots!
console.log(`I am ${} and leader of the ${transformer.fraction}!`);

August 1st, 2022

# Class attribute declaration

Add to bookmarks

In object-oriented programming, class attributes are often declared in the constructors. In JS, no constructor is needed.