DEV Community

Mahin Tazuar
Mahin Tazuar

Posted on

Javascript Getter and Setter

Today i am talking about javascript getter and getter.
Js Setter and getter using for highly manupulate javascript object value. We can calculate js object value using this two things.


class Thermostat {
    constructor(fahrenheit) {
      this.fahrenheit = fahrenheit;
    }

    get temperature() {
      return (5 / 9) * (this.fahrenheit - 32);
    }

    set temperature(celsius) {
      this.fahrenheit = (celsius * 9.0) / 5 + 32;
    }
  }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)