Javascript Getter and Setter

mahin678

Mahin Tazuar

Posted on December 23, 2021

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
💖 💪 🙅 🚩
mahin678
Mahin Tazuar

Posted on December 23, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related