JS Built-ins
Prototypesadvanced

Prototypes β€” Static methods

πŸ“– Usage Example
class MathHelper {
  static square(n) { return n * n; }
}
MathHelper.square(4); // 16

Static methods belong to the class itself, not to any instance.

Static Methods on Classes

Static methods belong to the class itself, not to instances. They're useful for utility functions or factory methods that relate to the class but don't need instance data.

Challenge: Create a class with static methods for creating instances or performing calculations.

πŸ’‘ Hints (3)
  • β€’ Static methods use the static keyword
  • β€’ They are called on the class, not instances
  • β€’ this inside static method refers to the class