Course contentsShow
← JavaScript
Lesson 783 of 2,72318. ClassesFree lesson

Static Methods Cannot Access Instance Properties

Static methods have no access to instance properties or 'this' in the context of an instance.

You'll Learn Why Static Methods Can't Touch Instance Data

Static methods belong to the class itself, not to any particular object created from that class. Because they're not attached to an instance, they have no way to access properties stored on individual objects.

The Core Problem

Think of a static method like a photocopier's instruction manual bolted to the wall of an office. The manual (static method) knows how to use any photocopier in general, but it can't tell you how much paper is left in the specific machine at your desk—it's not connected to any particular copier.

When you call a static method, there's no this bound to an instance. The method lives "above" the individual objects, so it can't reach down into them.

class BankAccount {
  constructor(balance) {
    this.balance = balance; // instance property
  }

  withdraw(amount) {
    this.balance -= amount; // instance method CAN access this.balance
  }

  static getAccountType() {
    console.log(this.balance); // undefined! No instance here
    return "Standard";
  }
}

const myAccount = new BankAccount(1000);
myAccount.withdraw(50); // ✓ Works: instance method with this

BankAccount.getAccountType(); // ✓ Calls successfully, but this.balance is undefined

Inside getAccountType(), this refers to the BankAccount class itself, not to myAccount. The balance property only exists on instances like myAccount, not on the class.

The Workaround

If a static method needs instance data, it must receive an instance as a parameter:

static displayBalance(account) {
  console.log(account.balance); // ✓ Now it works
}

BankAccount.displayBalance(myAccount); // Pass the instance explicitly

Key Takeaway: Static methods operate at the class level and have no access to instance properties or the instance's this context—they can only work with data passed to them as parameters.