Private Static Methods
You'll learn how to create truly private utility methods at the class level that can't be accessed from outside the class.
What Are Private Static Methods?
Just as you can have private instance methods (using #methodName) and static methods, you can combine both concepts into private static methods. These are class-level helper functions that only exist for internal class operations — they're not accessible from instances, subclasses, or external code.
Why Use Private Static Methods?
Think of a private static method like a backstage crew member who operates equipment that only the theater itself uses — not individual actors (instances) and not visible to the audience (external code). These methods perform internal class-level tasks that should stay completely hidden.
Syntax
Combine the # prefix with the static keyword:
class MathHelper {
static #validatePositive(num) {
if (num <= 0) throw new Error('Must be positive');
return true;
}
static calculateSquareRoot(num) {
this.#validatePositive(num);
return Math.sqrt(num);
}
}
MathHelper.calculateSquareRoot(16); // 4
// MathHelper.#validatePositive(5); // SyntaxError: Private field
The #validatePositive method is only callable from within the class itself, through other static methods using this.#methodName().
Key Characteristics
- Declared with
staticand#prefix - Only accessible within the class via
this.#methodName() - Cannot be called from instances, subclasses, or external code
- Perfect for internal validation, formatting, or calculation helpers
Key Takeaway: Private static methods encapsulate class-level utility logic that should remain completely hidden from the outside world, keeping your class's internal implementation details truly private.