Premium Only Content
Learn JavaScript STATIC keyword in 8 minutes! ⚡
// static = keyword that defines properties or methods that belong
// to a class itself rather than the objects created
// from that class (class owns anything static, not the objects)
// ----------- EXAMPLE 1 -----------
class MathUtil{
static PI = 3.14159;
static getDiameter(radius){
return radius * 2;
}
static getCircumference(radius){
return 2 * this.PI * radius;
}
static getArea(radius){
return this.PI * radius * radius;
}
}
console.log(MathUtil.PI);
console.log(MathUtil.getDiameter(10));
console.log(MathUtil.getCircumference(10));
console.log(MathUtil.getArea(10));
// ----------- EXAMPLE 2 -----------
class User{
static userCount = 0;
constructor(username){
this.username = username;
User.userCount++;
}
static getUserCount(){
console.log(`There are ${User.userCount} users online`);
}
sayHello(){
console.log(`Hello, my username is ${this.username}`);
}
}
const user1 = new User("Spongebob");
const user2 = new User("Patrick");
const user3 = new User("Sandy");
user1.sayHello();
user2.sayHello();
user3.sayHello();
User.getUserCount();
-
7:51
Dr. Nick Zyrowski
6 days agoHow To Starve Fat Cells - Not Yourself!
36.4K6 -
1:11:53
DeVory Darkins
2 hours agoBREAKING: Hegseth drops NIGHTMARE NEWS For Mark Kelly with potential court martial
91.6K41 -
LIVE
Dr Disrespect
4 hours ago🔴LIVE - DR DISRESPECT - ARC RAIDERS - BLUEPRINTS OR DEATH
2,738 watching -
1:10:26
Sean Unpaved
3 hours agoJalen Hurts & Eagles COLLAPSE In LOSS vs. Cowboys | UNPAVED
16.5K2 -
2:00:25
Steven Crowder
5 hours agoNo Influencer Safe: New X Update Exposed A Major Psyop
422K254 -
17:38
Professor Nez
3 hours agoTHIS will HAUNT Jasmine Crockett for Years...
14.9K20 -
56:36
The Rubin Report
4 hours agoTense Moment at Trump-Mamdani Meeting That No One Predicted
46.7K62 -
9:34
The White House
4 hours agoFirst Lady Melania Trump Welcomes the Official 2025 White House Christmas Tree
35.2K16 -
LIVE
LFA TV
17 hours agoLIVE & BREAKING NEWS! | MONDAY 11/24/25
1,944 watching -
1:01:32
VINCE
6 hours agoNew Info Blows the Lid Off The Butler Assassination Attempt | Episode 175 - 11/24/25 VINCE
267K241