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();
-
LIVE
Major League Fishing
4 days agoLIVE! - Fishing Clash Team Series: Heritage Cup - Day 1
3,104 watching -
18:40
itsSeanDaniel
3 hours agoPiers Morgan CALLED OUT and HUMILIATED by Andrew Tate
14.3K149 -
LIVE
Times Now World
2 days agoLIVE: "ON CAM: How the Charlie Kirk Shooter ESCAPED – Shocking New Footage Revealed!"
376 watching -
1:45:51
Game On!
22 hours ago $10.16 earnedWise Guys Reveal NFL Week 2 BEST BETS Now
56.4K7 -
26:57
Robbi On The Record
2 days agoMouth Breathing Is Why You’re Exhausted | with Dr. Melanie Silvestrini
20.3K5 -
LIVE
Total Horse Channel
6 hours ago2025 Reno Snaffle Bit Futurity | Sunday Finals
139 watching -
40:44
SouthernbelleReacts
7 days ago $2.84 earned“Event Horizon (1997) Reaction | Hellraiser in Space with Sam Neill & Laurence Fishburne”
29.6K4 -
10:49
Artur Stone Garage
3 days ago $2.02 earnedI Spent $2000 on My Turbo Honda Civic Build (Before & After)
29.8K9 -
0:44
Danny Rayes
18 hours ago $3.25 earnedDid Someone Know It Was Going To Happen?
31.5K10 -
15:03
World2Briggs
1 day ago $2.91 earnedShocking Home Prices in Florida's Cheapest Towns!
28.1K6