Key Concepts

Review core concepts you need to learn to master this subject

Static Methods

class Dog { constructor(name) { this._name = name; } introduce() { console.log('This is ' + this._name + ' !'); } // A static method static bark() { console.log('Woof!'); } } const myDog = new Dog('Buster'); myDog.introduce(); // Calling the static method Dog.bark();

Within a JavaScript class, the static keyword defines a static method for a class. Static methods are not called on individual instances of the class, but are called on the class itself. Therefore, they tend to be general (utility) methods.

Lesson 1 of 1
  1. 1
    JavaScript is an object-oriented programming (OOP) language we can use to model real-world items. In this lesson, you will learn how to make classes. Classes are a tool that developers use to q…
  2. 2
    In the last exercise, you created a class called Dog, and used it to produce a Dog object. Although you may see similarities between class and object syntax, there is one important method that se…
  3. 3
    Now, we’re ready to create class instances. An instance is an object that contains the property names and methods of a class, but with unique property values. Let’s look at our Dog class example….
  4. 4
    At this point, we have a Dog class that spins up objects with name and behavior properties. Below, we will add getters and a method to bring our class to life. Class method and getter syntax is t…
  5. 5
    Finally, let’s use our new methods to access and manipulate data from Dog instances. class Dog { constructor(name) { this._name = name; this._behavior = 0; } get name() { re…
  6. 6
    Imagine our doggy daycare is so successful that we decide to expand the business and open a kitty daycare. Before the daycare opens, we need to create a Cat class so we can quickly generate Cat in…
  7. 7
    In the last exercise, we created a parent class named Animal for two child classes named Cat and Dog. The Animal class below contains the shared properties and methods of Cat and Dog. class Anima…
  8. 8
    We’ve abstracted the shared properties and methods of our Cat and Dog classes into a parent class called Animal (See below). class Animal { constructor(name) { this._name = name; this._b…
  9. 9
    Now that we know how to create an object that inherits properties from a parent class let’s turn our attention to methods. When we call extends in a class declaration, all of the parent methods ar…
  10. 10
    In addition to the inherited features, child classes can contain their own properties, getters, setters, and methods. Below, we will add a usesLitter getter. The syntax for creating getters, sett…
  11. 11
    Sometimes you will want a class to have methods that aren’t available in individual instances, but that you can call directly from the class. Take the Date class, for example — you can both…
  12. 12
    Way to go! Let’s review what you learned. - Classes are templates for objects. - Javascript calls a constructor method when we create a new instance of a class. - Inheritance is when we cre…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo