1

As a developer in C#, I am shifting to learning JavaScript. Here is a piece of code in C#:

public string Name { get; set; }

How would I transform this code(getters/setters) to JavaScript?

Ashu Mundra
  • 45
  • 1
  • 5
  • 1
    I would start with the documentation, and go from there. [Getter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) and [Setter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set) – devlin carnate Mar 19 '20 at 18:13

1 Answers1

2
  #name = "initial";
  get name() { return this.#name; };
  set name(value) { this.#name = value; };

That would be the closest Javascript, using private class properties and class getter / setters.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151