30 Days Of JavaScript

Day 12: Classes

Lesson 4: Static

When we call const t = new Triangle(10, 10) we are calling the class constructor to give us a new Triangle instance.

When we call t.width we are accessing the width property of that specific instance of Triangle.

When we call t.area() we are calling the area() method of that specific instance of Triangle.

So the constructor is called on the class and the others are called on the instance. We area able to add other functionality to the class with the word static. For example we might want to ask the triangle class some information about it's self.

And you can do the same with methods. For instance we could have a method to calculate the area differences between two triangles like this.


Go Pro?

Upgrade to Pro for quizzes, tracked progress and a completion certificate for just $25 🚀

Want more developer tips, tricks and tools?
Then follow me:
FREE Coding Career Quick Start Guide 🚀
Discover the best way to learn to code, how to land a job and valuable resources to help your journey in this free 15 page value packed guide.
Looking to email me? You can get me on my first name at allthecode.co