Skip to content
Advertisement

What is the difference between class fields and properties in Javascript

I’m reading class fields proposal for JavaScript. I don’t understand why the authors call it ‘fields’ and not properties.

MDN docs in class article speak about instance properties declared inside constructor and in next section about field declarations declared using new syntax.

What is the difference between the two besides the syntax?

Advertisement

Answer

What is the difference between the two besides the syntax?

There isn’t any. A public field is an instance property, just one created with a field definition rather than by assignment. Other than how they’re created, they’re exactly the same thing.

The term “field” was used so it could cover both public and private (since private fields are not properties).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement