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)

Want to Create an Account?
Now it's your turn!
Β 
πŸ—’ Share a tutorial
πŸ€” Reflect on your coding journey
❓ Ask a question

Create an account to join hundreds of thousands of DEV members on their journey.