Runtime 58 ms Beats 17.19% & Memory 48.94 MB Beats 41.58%
ApproachMethod chaining in JavaScript classes allows you to call multiple methods on the same instance in a single statement. This is typically achieved by havi

# Approach
Method chaining in JavaScript classes allows you to call multiple methods on the same instance in a single statement. This is typically achieved by having each method return the instance (this) so you can chain further method calls.

# Code
```javascript []
class Calculator {
  /**
   * @param {number} value
   */
  constructor(value) {
    this.result = value;
  }

  /**
   * @param {number} value
   * @return {Calculator}
   */
  add(value) {
    this.result += value;
    return this;
  }

  /**
   * @param {number} value
   * @return {Calculator}
   */
  subtract(value) {
    this.result -= value;
    return this;
  }

  /**
   * @param {number} value
   * @return {Calculator}
   */
  multiply(value) {
    this.result *= value;
    return this;
  }

  /**
   * @param {number} value
   * @return {Calculator}
   */
  divide(value) {
    if (value !== 0) {
      this.result /= value;
      return this;
    } else {
      throw new Error("Division by zero is not allowed");
    }
  }

  /**
   * @param {number} value
   * @return {Calculator}
   */
  power(value) {
    this.result **= value;
    return this;
  }

  /**
   * @return {number}
   */
  getResult() {
    return this.result;
  }
}

```
['JavaScript']